diff --git a/.github/workflows/core12.yml b/.github/workflows/core12.yml index 11cb74a32..03b1fd2e7 100644 --- a/.github/workflows/core12.yml +++ b/.github/workflows/core12.yml @@ -18,7 +18,7 @@ jobs: uses: actions/checkout@v3 - name: Install testing system - run: Build/Scripts/runTests.sh -t 12 -p ${{ matrix.php }} -s ${{ matrix.composerInstall }} + run: Build/Scripts/runTests.sh -t 12 -p ${{ matrix.php }} -s ${{ matrix.composerInstall }} - name: Lint PHP run: Build/Scripts/runTests.sh -t 12 -p ${{ matrix.php }} -s lint @@ -27,6 +27,15 @@ jobs: name: Validate code against CGL run: PHP_CS_FIXER_IGNORE_ENV=1 Build/Scripts/runTests.sh -t 12 -p ${{ matrix.php }} -s cgl -n + # temporary composer require here until rector supports nikic/php-parser ^5.1.0 for TYPO3 13 compatibility + - if: matrix.php == '8.1' && matrix.composerInstall == 'composerInstallHighest' + name: Install Rector + run: composer require ssch/typo3-rector --dev + + - if: matrix.php == '8.1' && matrix.composerInstall == 'composerInstallHighest' + name: Run Rector + run: Build/Scripts/runTests.sh -t 12 -p ${{ matrix.php }} -s rector -n + - name: Unit Tests run: Build/Scripts/runTests.sh -t 12 -p ${{ matrix.php }} -s unit diff --git a/Build/Scripts/runTests.sh b/Build/Scripts/runTests.sh index 4cdfe67bf..dce8bb68f 100755 --- a/Build/Scripts/runTests.sh +++ b/Build/Scripts/runTests.sh @@ -170,6 +170,7 @@ Options: - composerInstallHighest: "composer update", handy if host has no PHP - coveralls: Generate coverage - docsGenerate: Renders the extension ReST documentation. + - rector: Run rector - functional: functional tests - lint: PHP linting - unit: PHP unit tests @@ -228,10 +229,9 @@ Options: - 12: use TYPO3 v12 (default) - 13: use TYPO3 v13 - -p <8.0|8.1|8.2|8.3|8.4> + -p <8.1|8.2|8.3|8.4> Specifies the PHP minor version to be used - - 8.0: use PHP 8.0 (default) - - 8.1: use PHP 8.1 + - 8.1: use PHP 8.1 (default) - 8.2: use PHP 8.2 - 8.3: use PHP 8.3 - 8.4: use PHP 8.4 @@ -271,7 +271,7 @@ Options: Show this help. Examples: - # Run all core unit tests using PHP 7.4 + # Run all core unit tests ./Build/Scripts/runTests.sh -s unit # Run all core units tests and enable xdebug (have a PhpStorm listening on port 9003!) @@ -314,7 +314,7 @@ PHP_VERSION="8.1" PHP_XDEBUG_ON=0 PHP_XDEBUG_PORT=9003 EXTRA_TEST_OPTIONS="" -CGLCHECK_DRY_RUN=0 +DRY_RUN=0 DATABASE_DRIVER="" CONTAINER_BIN="" COMPOSER_ROOT_VERSION="12.0.0-dev" @@ -377,7 +377,7 @@ while getopts "a:b:s:d:i:p:e:t:xy:nhu" OPT; do PHP_XDEBUG_PORT=${OPTARG} ;; n) - CGLCHECK_DRY_RUN=1 + DRY_RUN=1 ;; h) loadHelp @@ -470,7 +470,7 @@ fi case ${TEST_SUITE} in cgl) DRY_RUN_OPTIONS='' - if [ "${CGLCHECK_DRY_RUN}" -eq 1 ]; then + if [ "${DRY_RUN}" -eq 1 ]; then DRY_RUN_OPTIONS='--dry-run --diff' fi COMMAND="php -dxdebug.mode=off .Build/bin/php-cs-fixer fix -v ${DRY_RUN_OPTIONS} --config=Build/php-cs-fixer/php-cs-fixer.php --using-cache=no" @@ -588,6 +588,15 @@ case ${TEST_SUITE} in ${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name composer-command-${SUFFIX} -e COMPOSER_CACHE_DIR=.cache/composer -e COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION} ${IMAGE_PHP} /bin/bash -c "${COMMAND}" SUITE_EXIT_CODE=$? ;; + rector) + DRY_RUN_OPTIONS='' + if [ "${DRY_RUN}" -eq 1 ]; then + DRY_RUN_OPTIONS='--dry-run' + fi + COMMAND="php -dxdebug.mode=off .Build/bin/rector process ${DRY_RUN_OPTIONS} --config=Build/rector/rector.php --no-progress-bar --ansi" + ${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name composer-command-${SUFFIX} -e COMPOSER_CACHE_DIR=.cache/composer -e COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION} ${IMAGE_PHP} /bin/sh -c "${COMMAND}" + SUITE_EXIT_CODE=$? + ;; unit) COMMAND=(.Build/bin/phpunit -c Build/phpunit/UnitTests.xml --exclude-group not-${DBMS} ${EXTRA_TEST_OPTIONS} "$@") ${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name unit-${SUFFIX} ${XDEBUG_MODE} -e XDEBUG_CONFIG="${XDEBUG_CONFIG}" ${IMAGE_PHP} "${COMMAND[@]}" diff --git a/Build/rector/rector.php b/Build/rector/rector.php new file mode 100644 index 000000000..3d6483eb6 --- /dev/null +++ b/Build/rector/rector.php @@ -0,0 +1,54 @@ +withPaths([ + __DIR__ . '/../../Build', + __DIR__ . '/../../Classes', + __DIR__ . '/../../Configuration', + __DIR__ . '/../../Tests', + __DIR__ . '/../../ext_emconf.php', + __DIR__ . '/../../ext_localconf.php', + __DIR__ . '/../../ext_tables.php', + ]) + //->withPhpSets(php81: true) + ->withPhpVersion(PhpVersion::PHP_81) + ->withSets([ + Typo3SetList::CODE_QUALITY, + Typo3SetList::GENERAL, + Typo3LevelSetList::UP_TO_TYPO3_12, + ]) + // To have a better analysis from PHPStan, we teach it here some more things + ->withPHPStanConfigs([Typo3Option::PHPSTAN_FOR_RECTOR_PATH]) + ->withRules([ + ConvertImplicitVariablesToExplicitGlobalsRector::class, + ]) + ->withImportNames(true, true, false, true) + ->withConfiguredRule(ExtEmConfRector::class, [ + ExtEmConfRector::PHP_VERSION_CONSTRAINT => '8.1.0-8.4.99', + ExtEmConfRector::TYPO3_VERSION_CONSTRAINT => '12.4.2-13.9.99', + ExtEmConfRector::ADDITIONAL_VALUES_TO_BE_REMOVED => [], + ]) + ->withSkip([ + InjectMethodToConstructorInjectionRector::class => [ + __DIR__ . '/../../Classes/Controller/AdministrationController.php', + __DIR__ . '/../../Classes/Domain/Repository/AbstractDemandedRepository.php', + __DIR__ . '/../../Classes/Service/SettingsService.php', + __DIR__ . '/../../Classes/ViewHelpers/', + ], + DateTimeAspectInsteadOfGlobalsExecTimeRector::class => [ + __DIR__ . '/../../Tests/Unit/Backend/FormDataProvider/NewsRowInitializeNewTest.php', + ], + ]) +;