From 6fc0d3b954ff4b8543dcb6dac81f6a64ba21b796 Mon Sep 17 00:00:00 2001 From: Sybille Date: Sun, 27 Oct 2024 17:15:09 +0100 Subject: [PATCH] [FEATURE] Make ready for v13 (#387) * [FEATURE] Make ready for v13 * Add CI test for v12 and v13 * Remove prophecy for v13 * Use PHP 8.3 for cgl tests * Remove prophecy from phpstan * Use DI in constuctors * Support up to PHP 8.3 --- .github/workflows/ci.yml | 95 ++++++++++++++++--- Build/Scripts/runTests.sh | 6 +- Build/phpstan/phpstan.neon | 2 +- .../Controller/BrokenLinkListController.php | 30 +++--- .../Controller/ManageExclusionsController.php | 33 ++++--- .../MissingConfigurationException.php | 15 +-- Classes/Linktype/AbstractLinktype.php | 4 +- Classes/Linktype/ExternalLinktype.php | 8 +- Classes/Linktype/FileLinktype.php | 4 +- Classes/Linktype/InternalLinktype.php | 3 +- Classes/Linktype/LinktypeInterface.php | 15 +-- Classes/Mail/GenerateCheckResultFluidMail.php | 20 +--- composer.json | 11 +-- ext_emconf.php | 2 +- 14 files changed, 136 insertions(+), 112 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 53980d4f6..f1784dc78 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,20 +9,20 @@ on: push: pull_request: schedule: - - cron: '42 5 * * *' + - cron: '42 5 * * 1' jobs: - all_core_12: + static: # only run jobs via scheduled workflow in main repo, not in forks if: (github.event_name == 'schedule' && github.repository == 'sypets/brofix') || (github.event_name != 'schedule') - name: "all core-12" + name: "static" runs-on: ubuntu-20.04 strategy: # This prevents cancellation of matrix job runs, if one/two already failed and let the # rest matrix jobs be be executed anyway. - fail-fast: false + fail-fast: true matrix: - php: [ '8.1', '8.2' ] + php: [ '8.3' ] minMax: [ 'composerInstallMax' ] steps: - name: "Checkout" @@ -50,6 +50,32 @@ jobs: if: always() run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s composerValidate + + all_core_latest: + # only run jobs via scheduled workflow in main repo, not in forks + if: (github.event_name == 'schedule' && github.repository == 'sypets/brofix') || (github.event_name != 'schedule') + name: "all core-latest" + runs-on: ubuntu-20.04 + strategy: + # This prevents cancellation of matrix job runs, if one/two already failed and let the + # rest matrix jobs be be executed anyway. + fail-fast: true + matrix: + php: [ '8.2', '8.3' ] + minMax: [ 'composerInstallMax' ] + steps: + - name: "Checkout" + uses: actions/checkout@v2 + + - name: "show php version" + run: php --version + + #- name: "Set Typo3 core version" + # run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -t "^11.5" -s composerCoreVersion + + - name: "Composer" + run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s ${{ matrix.minMax }} + - name: "Lint PHP" if: always() run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s lint @@ -58,6 +84,57 @@ jobs: if: ${{ always() && matrix.minMax == 'composerInstallMax' }} run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s phpstan -e "--error-format=github" -v + # todo: replace prophecy + + #- name: "Unit tests" + # if: always() + # run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s unit -v + + #- name: "Functional tests with mariadb" + # if: always() + # run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -d mariadb -s functional -v + + #- name: "Functional tests with sqlite (nightly or pull_request)" + # if: ${{ always() && (github.event_name == 'schedule' || github.event_name == 'pull_request' ) }} + # run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -d sqlite -s functional + + #- name: "Functional tests with postgres (nightly or pull_request)" + # if: ${{ always() && (github.event_name == 'schedule' || github.event_name == 'pull_request' ) }} + # run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -d postgres -s functional + + # v12 + all_core_v12: + # only run jobs via scheduled workflow in main repo, not in forks + if: (github.event_name == 'schedule' && github.repository == 'sypets/brofix') || (github.event_name != 'schedule') + name: "all core-v12" + runs-on: ubuntu-20.04 + strategy: + # This prevents cancellation of matrix job runs, if one/two already failed and let the + # rest matrix jobs be be executed anyway. + fail-fast: true + matrix: + php: [ '8.1', '8.3' ] + minMax: [ 'composerInstallMax' ] + steps: + - name: "Checkout" + uses: actions/checkout@v2 + + - name: "show php version" + run: php --version + + - name: "Set Typo3 core version" + run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -t "^12.4" -s composerCoreVersion + + - name: "Add prophecy for unit / functional tests" + run: composer require --dev jangregor/phpstan-prophecy phpspec/prophecy phpspec/prophecy-phpunit + + - name: "Composer" + run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s ${{ matrix.minMax }} + + - name: "phpstan" + if: ${{ always() && matrix.minMax == 'composerInstallMax' }} + run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s phpstan -e "--error-format=github" -v + - name: "Unit tests" if: always() run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s unit -v @@ -65,11 +142,3 @@ jobs: - name: "Functional tests with mariadb" if: always() run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -d mariadb -s functional -v - - - name: "Functional tests with sqlite (nightly or pull_request)" - if: ${{ always() && (github.event_name == 'schedule' || github.event_name == 'pull_request' ) }} - run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -d sqlite -s functional - - - name: "Functional tests with postgres (nightly or pull_request)" - if: ${{ always() && (github.event_name == 'schedule' || github.event_name == 'pull_request' ) }} - run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -d postgres -s functional diff --git a/Build/Scripts/runTests.sh b/Build/Scripts/runTests.sh index d070b5a68..49d0f63bd 100755 --- a/Build/Scripts/runTests.sh +++ b/Build/Scripts/runTests.sh @@ -4,10 +4,10 @@ # config -SUPPORTED_PHP_VERSIONS="8.1|8.2|8.3" -DEFAULT_PHP_VERSION="8.1" +SUPPORTED_PHP_VERSIONS="8.1|8.2|8.3|8.4" +DEFAULT_PHP_VERSION="8.3" PHP_VERSION="${DEFAULT_PHP_VERSION}" -DEFAULT_PHP_PLATFORM_VERSION="8.2.15" +DEFAULT_PHP_PLATFORM_VERSION="8.3.0" # Function to write a .env file in Build/testing-docker/local diff --git a/Build/phpstan/phpstan.neon b/Build/phpstan/phpstan.neon index 517f0c497..01871db2b 100644 --- a/Build/phpstan/phpstan.neon +++ b/Build/phpstan/phpstan.neon @@ -1,7 +1,7 @@ includes: # regenerate baseline with: Build/Scripts/runTests.sh -s phpstanGenerateBaseline #- phpstan-baseline.neon - - ../../.Build/vendor/jangregor/phpstan-prophecy/extension.neon + #- ../../.Build/vendor/jangregor/phpstan-prophecy/extension.neon parameters: # Use local cache dir instead of /tmp diff --git a/Classes/Controller/BrokenLinkListController.php b/Classes/Controller/BrokenLinkListController.php index c60170a68..5662271d5 100644 --- a/Classes/Controller/BrokenLinkListController.php +++ b/Classes/Controller/BrokenLinkListController.php @@ -205,29 +205,25 @@ class BrokenLinkListController extends AbstractBrofixController protected bool $backendUserHasPermissionsForExcludes = false; public function __construct( - PagesRepository $pagesRepository = null, - BrokenLinkRepository $brokenLinkRepository = null, - ExcludeLinkTarget $excludeLinkTarget = null, - FlashMessageService $flashMessageService = null, + PagesRepository $pagesRepository, + BrokenLinkRepository $brokenLinkRepository, + ExcludeLinkTarget $excludeLinkTarget, + FlashMessageService $flashMessageService, ModuleTemplateFactory $moduleTemplateFactory, - IconFactory $iconFactory = null, - ExtensionConfiguration $extensionConfiguration = null, - PageRenderer $pageRenderer = null + IconFactory $iconFactory, + ExtensionConfiguration $extensionConfiguration, + PageRenderer $pageRenderer ) { - $this->pageRenderer = $pageRenderer ?: GeneralUtility::makeInstance(PageRenderer::class); - $iconFactory = $iconFactory ?: GeneralUtility::makeInstance(IconFactory::class); - $excludeLinkTarget = $excludeLinkTarget ?: GeneralUtility::makeInstance(ExcludeLinkTarget::class); + $this->pageRenderer = $pageRenderer; + $iconFactory = $iconFactory; + $excludeLinkTarget = $excludeLinkTarget; $moduleTemplateFactory = $moduleTemplateFactory; - $this->brokenLinkRepository = $brokenLinkRepository ?: GeneralUtility::makeInstance(BrokenLinkRepository::class); - $this->pagesRepository = $pagesRepository ?: GeneralUtility::makeInstance(PagesRepository::class); - $flashMessageService = $flashMessageService ?: GeneralUtility::makeInstance(FlashMessageService::class); + $this->brokenLinkRepository = $brokenLinkRepository; + $this->pagesRepository = $pagesRepository; + $this->defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier(); $this->orderBy = BrokenLinkListController::DEFAULT_ORDER_BY; - // configuration / extension configuration - if (!$extensionConfiguration) { - $extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class); - } $extConfArray = $extensionConfiguration->get('brofix') ?: []; $configuration = GeneralUtility::makeInstance(Configuration::class, $extConfArray); diff --git a/Classes/Controller/ManageExclusionsController.php b/Classes/Controller/ManageExclusionsController.php index e35834e23..2aaec9f05 100644 --- a/Classes/Controller/ManageExclusionsController.php +++ b/Classes/Controller/ManageExclusionsController.php @@ -91,27 +91,26 @@ class ManageExclusionsController extends AbstractBrofixController protected bool $backendUserHasPermissions = false; public function __construct( - ExcludeLinkTargetRepository $excludeLinkTargetRepository = null, - ManageExclusionsFilter $filter = null, - ExtensionConfiguration $extensionConfiguration = null, + ExcludeLinkTargetRepository $excludeLinkTargetRepository, + ManageExclusionsFilter $filter, + ExtensionConfiguration $extensionConfiguration, ModuleTemplateFactory $moduleTemplateFactory, - IconFactory $iconFactory = null, - ExcludeLinkTarget $excludeLinkTarget = null, - CharsetConverter $charsetConverter = null, - LocalizationUtility $localizationUtility = null, - PageRenderer $pageRenderer = null + IconFactory $iconFactory, + ExcludeLinkTarget $excludeLinkTarget, + CharsetConverter $charsetConverter, + LocalizationUtility $localizationUtility, + PageRenderer $pageRenderer ) { - $this->pageRenderer = $pageRenderer ?: GeneralUtility::makeInstance(PageRenderer::class); - $iconFactory = $iconFactory ?: GeneralUtility::makeInstance(IconFactory::class); + $this->pageRenderer = $pageRenderer; + $iconFactory = $iconFactory; $moduleTemplateFactory = $moduleTemplateFactory; - $excludeLinkTarget = $excludeLinkTarget ?: GeneralUtility::makeInstance(ExcludeLinkTarget::class); - $this->excludeLinkTargetRepository = $excludeLinkTargetRepository ?: GeneralUtility::makeInstance(ExcludeLinkTargetRepository::class); - $this->filter = $filter ?: GeneralUtility::makeInstance(ManageExclusionsFilter::class); - $this->charsetConverter = $charsetConverter ?? GeneralUtility::makeInstance(CharsetConverter::class); - $this->localizationUtility = $localizationUtility ?? GeneralUtility::makeInstance(LocalizationUtility::class); - $this->orderBy = ManageExclusionsController::ORDER_BY_DEFAULT; + $excludeLinkTarget = $excludeLinkTarget; + $this->excludeLinkTargetRepository = $excludeLinkTargetRepository; + $this->filter = $filter; + $this->charsetConverter = $charsetConverter; + $this->localizationUtility = $localizationUtility; - $extensionConfiguration = $extensionConfiguration ?: GeneralUtility::makeInstance(ExtensionConfiguration::class); + $this->orderBy = ManageExclusionsController::ORDER_BY_DEFAULT; $extConfArray = $extensionConfiguration->get('brofix') ?: []; $configuration = GeneralUtility::makeInstance(Configuration::class, $extConfArray); diff --git a/Classes/Exceptions/MissingConfigurationException.php b/Classes/Exceptions/MissingConfigurationException.php index cf1b0a8aa..7030ca579 100644 --- a/Classes/Exceptions/MissingConfigurationException.php +++ b/Classes/Exceptions/MissingConfigurationException.php @@ -3,22 +3,9 @@ declare(strict_types=1); namespace Sypets\Brofix\Exceptions; -/* - * This file is part of the TYPO3 CMS project. - * - * It is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. - * - * For the full copyright and license information, please read the - * LICENSE.txt file that was distributed with this source code. - * - * The TYPO3 project - inspiring people to share! - */ - class MissingConfigurationException extends \Exception { - public function __construct(string $message = '', int $code = 0, \Throwable $previous = null) + public function __construct(string $message = '', int $code = 0, ?\Throwable $previous = null) { if ($message === '') { $message = 'Missing configuration'; diff --git a/Classes/Linktype/AbstractLinktype.php b/Classes/Linktype/AbstractLinktype.php index d188b0c8a..3a7ab0348 100644 --- a/Classes/Linktype/AbstractLinktype.php +++ b/Classes/Linktype/AbstractLinktype.php @@ -98,10 +98,10 @@ public function getBrokenUrl(array $row): string * Text to be displayed with the Link as anchor text * (not the real anchor text of the Link. * @param mixed[] $row - * @param mixed[] $additionalConfig + * @param array|null $additionalConfig * @return string */ - public function getBrokenLinkText(array $row, array $additionalConfig = null): string + public function getBrokenLinkText(array $row, ?array $additionalConfig = null): string { return $row['url']; } diff --git a/Classes/Linktype/ExternalLinktype.php b/Classes/Linktype/ExternalLinktype.php index 7e92a76c8..c8bb86d84 100644 --- a/Classes/Linktype/ExternalLinktype.php +++ b/Classes/Linktype/ExternalLinktype.php @@ -77,10 +77,10 @@ class ExternalLinktype extends AbstractLinktype implements LoggerAwareInterface protected $crawlDelay; public function __construct( - RequestFactory $requestFactory = null, - ExcludeLinkTarget $excludeLinkTarget = null, - LinkTargetCacheInterface $linkTargetCache = null, - CrawlDelay $crawlDelay = null + ?RequestFactory $requestFactory = null, + ?ExcludeLinkTarget $excludeLinkTarget = null, + ?LinkTargetCacheInterface $linkTargetCache = null, + ?CrawlDelay $crawlDelay = null ) { $this->requestFactory = $requestFactory ?: GeneralUtility::makeInstance(RequestFactory::class); $this->excludeLinkTarget = $excludeLinkTarget ?: GeneralUtility::makeInstance(ExcludeLinkTarget::class); diff --git a/Classes/Linktype/FileLinktype.php b/Classes/Linktype/FileLinktype.php index 26cd3b1ea..81c495ab8 100644 --- a/Classes/Linktype/FileLinktype.php +++ b/Classes/Linktype/FileLinktype.php @@ -95,10 +95,10 @@ public function getBrokenUrl(array $row): string * Text to be displayed with the Link as anchor text * (not the real anchor text of the Link. * @param mixed[] $row - * @param mixed[] $additionalConfig + * @param array|null $additionalConfig * @return string */ - public function getBrokenLinkText(array $row, array $additionalConfig = null): string + public function getBrokenLinkText(array $row, ?array $additionalConfig = null): string { return $this->getLanguageService()->sL('LLL:EXT:brofix/Resources/Private/Language/Module/locallang.xlf:list.report.url.file'); } diff --git a/Classes/Linktype/InternalLinktype.php b/Classes/Linktype/InternalLinktype.php index 7aecd06a3..8b93e7464 100644 --- a/Classes/Linktype/InternalLinktype.php +++ b/Classes/Linktype/InternalLinktype.php @@ -390,9 +390,10 @@ public function getBrokenUrl(array $row): string * Text to be displayed with the Link as anchor text * (not the real anchor text of the Link. * @param mixed[] $row + * @param array|null $additionalConfig * @return string */ - public function getBrokenLinkText(array $row, array $additionalConfig = null): string + public function getBrokenLinkText(array $row, ?array $additionalConfig = null): string { $pageTitle = $additionalConfig['page']['title'] ?? ''; $contentTitle = $additionalConfig['content']['title'] ?? ''; diff --git a/Classes/Linktype/LinktypeInterface.php b/Classes/Linktype/LinktypeInterface.php index 11b8ad443..5c35c053a 100644 --- a/Classes/Linktype/LinktypeInterface.php +++ b/Classes/Linktype/LinktypeInterface.php @@ -3,19 +3,6 @@ declare(strict_types=1); namespace Sypets\Brofix\Linktype; -/* - * This file is part of the TYPO3 CMS project. - * - * It is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. - * - * For the full copyright and license information, please read the - * LICENSE.txt file that was distributed with this source code. - * - * The TYPO3 project - inspiring people to share! - */ - use Sypets\Brofix\CheckLinks\LinkTargetResponse\LinkTargetResponse; use Sypets\Brofix\Configuration\Configuration; @@ -70,5 +57,5 @@ public function getBrokenUrl(array $row): string; * @param mixed[] $additionalConfig * @return string */ - public function getBrokenLinkText(array $row, array $additionalConfig = null): string; + public function getBrokenLinkText(array $row, ?array $additionalConfig = null): string; } diff --git a/Classes/Mail/GenerateCheckResultFluidMail.php b/Classes/Mail/GenerateCheckResultFluidMail.php index 3b36c6371..54fff0893 100644 --- a/Classes/Mail/GenerateCheckResultFluidMail.php +++ b/Classes/Mail/GenerateCheckResultFluidMail.php @@ -3,19 +3,6 @@ declare(strict_types=1); namespace Sypets\Brofix\Mail; -/* - * This file is part of the TYPO3 CMS project. - * - * It is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. - * - * For the full copyright and license information, please read the - * LICENSE.txt file that was distributed with this source code. - * - * The TYPO3 project - inspiring people to share! - */ - use Symfony\Component\Mailer\Exception\TransportExceptionInterface; use Symfony\Component\Mailer\SentMessage; use Symfony\Component\Mime\Address; @@ -24,13 +11,14 @@ use Sypets\Brofix\Exceptions\MissingConfigurationException; use TYPO3\CMS\Core\Mail\FluidEmail; use TYPO3\CMS\Core\Mail\Mailer; +use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\TemplatePaths; /** * Send mail with Fluid */ -class GenerateCheckResultFluidMail +class GenerateCheckResultFluidMail implements SingletonInterface { /** * @var Mailer @@ -42,9 +30,9 @@ class GenerateCheckResultFluidMail */ protected $messageId; - public function __construct(Mailer $mailer = null) + public function __construct(Mailer $mailer) { - $this->mailer = $mailer ?: GeneralUtility::makeInstance(Mailer::class); + $this->mailer = $mailer; } public function getMessageId(): string diff --git a/composer.json b/composer.json index c71c202e9..93e42c2d3 100644 --- a/composer.json +++ b/composer.json @@ -34,17 +34,14 @@ } }, "require": { - "php": "^8.1", - "typo3/cms-backend": "^12.4.1", - "typo3/cms-core": "^12.4.1", - "typo3/cms-fluid": "^12.4.1" + "php": "~8.1.0 || ~8.2.0 || ~8.3.0", + "typo3/cms-backend": "^12.4.1 || ^13.4", + "typo3/cms-core": "^12.4.1 || ^13.4", + "typo3/cms-fluid": "^12.4.1 || ^13.4" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.2", "friendsoftypo3/phpstan-typo3": "^0.9.0", - "jangregor/phpstan-prophecy": "^1.0.0", - "phpspec/prophecy": "^1.15.0", - "phpspec/prophecy-phpunit": "^2.0.1", "phpstan/phpstan": "^1.8.2", "phpunit/phpunit": "^9.5.20", "ssch/typo3-rector": "^1.2", diff --git a/ext_emconf.php b/ext_emconf.php index d90edd036..6cbdba54e 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -14,7 +14,7 @@ 'version' => '6.2.0', 'constraints' => [ 'depends' => [ - 'typo3' => '12.4.4-12.9.99', + 'typo3' => '12.4.4-13.9.99', ], 'conflicts' => [], 'suggests' => [