From 207ad079a0d921a509692b89fbd3452980aaf4c8 Mon Sep 17 00:00:00 2001 From: Tobias Wojtylak Date: Mon, 1 Jul 2024 15:19:32 +0200 Subject: [PATCH] fix(v12): use typo3 12 --- .../Query/Restriction/SiteRestriction.php | 2 +- .../TypoScriptFrontendInitialization.php | 7 +++++- Tests/Acceptance/Api.suite.yml | 2 +- Tests/Acceptance/Support/Helper/ApiAccess.php | 2 +- .../Unit/Middleware/LanguageResolverTest.php | 22 +++++++++++++++---- .../TypoScriptFrontendInitializationTest.php | 11 ++++++++-- Tests/codeception.yml | 1 + composer.json | 21 +++++++++++------- etc/testing-docker/docker-compose.yml | 3 +-- 9 files changed, 51 insertions(+), 20 deletions(-) diff --git a/Classes/Database/Query/Restriction/SiteRestriction.php b/Classes/Database/Query/Restriction/SiteRestriction.php index 35be7d5..089c1da 100644 --- a/Classes/Database/Query/Restriction/SiteRestriction.php +++ b/Classes/Database/Query/Restriction/SiteRestriction.php @@ -62,7 +62,7 @@ private function getSitePids(): array return []; } - $this->cachedSitePids = $this->pageRepository->getPageIdsRecursive($site->getRootPageId(), 999); + $this->cachedSitePids = $this->pageRepository->getPageIdsRecursive([$site->getRootPageId()], 999); return $this->cachedSitePids; } diff --git a/Classes/Middleware/TypoScriptFrontendInitialization.php b/Classes/Middleware/TypoScriptFrontendInitialization.php index 80ab3fb..df45490 100644 --- a/Classes/Middleware/TypoScriptFrontendInitialization.php +++ b/Classes/Middleware/TypoScriptFrontendInitialization.php @@ -28,7 +28,12 @@ public function __construct(Context $context) public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $tsfe = $this->getTyposcriptFrontendController($request); - $tsfe->determineId(); + + try { + $tsfe->determineId($request); + } catch (\Exception $e) { + // v12: not sure if the `determineId` call is still necessary in v12 + } return $handler->handle($request); } diff --git a/Tests/Acceptance/Api.suite.yml b/Tests/Acceptance/Api.suite.yml index 049ec4f..da831f4 100644 --- a/Tests/Acceptance/Api.suite.yml +++ b/Tests/Acceptance/Api.suite.yml @@ -1,4 +1,4 @@ -class_name: ApiTester +actor: ApiTester modules: enabled: - Asserts diff --git a/Tests/Acceptance/Support/Helper/ApiAccess.php b/Tests/Acceptance/Support/Helper/ApiAccess.php index cb9a7fd..d0923cd 100644 --- a/Tests/Acceptance/Support/Helper/ApiAccess.php +++ b/Tests/Acceptance/Support/Helper/ApiAccess.php @@ -9,7 +9,7 @@ class ApiAccess extends Module { - protected $requiredFields = ['grant_type', 'client_id', 'client_secret']; + protected array $requiredFields = ['grant_type', 'client_id', 'client_secret']; public function grabValidCredentials(): array { diff --git a/Tests/Unit/Middleware/LanguageResolverTest.php b/Tests/Unit/Middleware/LanguageResolverTest.php index f08aaf8..f670403 100644 --- a/Tests/Unit/Middleware/LanguageResolverTest.php +++ b/Tests/Unit/Middleware/LanguageResolverTest.php @@ -158,9 +158,16 @@ public function it_will_set_language_by_href_lang(): void ->method('setAspect') ->with('language', self::isInstanceOf(LanguageAspect::class)); - $requestMock->expects(self::exactly(2)) + $matcher = self::exactly(2); + + $requestMock->expects($matcher) ->method('withAttribute') - ->withConsecutive(['context', $this->contextMock], ['language', $siteLanguageMock]) + ->willReturnCallback(function (string $key, string $value) use ($matcher, $siteLanguageMock) { + match ($matcher->numberOfInvocations()) { + 1 => $this->assertEquals(['context', $this->contextMock], [$key, $value]), + 2 => $this->assertEquals(['language', $siteLanguageMock], [$key, $value]), + }; + }) ->willReturn($requestMock); $this->subject->process($requestMock, $requestHandlerMock); @@ -208,9 +215,16 @@ public function it_will_set_language_by_two_letter_iso_code(): void ->method('setAspect') ->with('language', self::isInstanceOf(LanguageAspect::class)); - $requestMock->expects(self::exactly(2)) + $matcher = self::exactly(2); + + $requestMock->expects($matcher) ->method('withAttribute') - ->withConsecutive(['context', $this->contextMock], ['language', $siteLanguageMock]) + ->willReturnCallback(function (string $key, string $value) use ($matcher, $siteLanguageMock) { + match ($matcher->numberOfInvocations()) { + 1 => $this->assertEquals(['context', $this->contextMock], [$key, $value]), + 2 => $this->assertEquals(['language', $siteLanguageMock], [$key, $value]), + }; + }) ->willReturn($requestMock); $this->subject->process($requestMock, $requestHandlerMock); diff --git a/Tests/Unit/Middleware/TypoScriptFrontendInitializationTest.php b/Tests/Unit/Middleware/TypoScriptFrontendInitializationTest.php index cd9f745..08bc65b 100644 --- a/Tests/Unit/Middleware/TypoScriptFrontendInitializationTest.php +++ b/Tests/Unit/Middleware/TypoScriptFrontendInitializationTest.php @@ -50,9 +50,16 @@ public function it_will_init_typoscript_frontend_on_process(): void $frontendControllerMock = $this->createMock(TypoScriptFrontendController::class); GeneralUtility::addInstance(TypoScriptFrontendController::class, $frontendControllerMock); - $requestMock + $matcher = self::exactly(3); + + $requestMock->expects($matcher) ->method('getAttribute') - ->withConsecutive(['site'], ['language']) + ->willReturnCallback(function (string $key, string $value) use ($matcher, $siteLanguageMock) { + match ($matcher->numberOfInvocations()) { + 1 => $this->assertEquals('site', $value), + 2 => $this->assertEquals('language', $value), + }; + }) ->willReturnOnConsecutiveCalls($siteMock, $pageArgumentsMock, $siteLanguageMock); $this->subject->process($requestMock, $requestHandlerMock); diff --git a/Tests/codeception.yml b/Tests/codeception.yml index 2dc7fd0..40a78d4 100644 --- a/Tests/codeception.yml +++ b/Tests/codeception.yml @@ -3,6 +3,7 @@ paths: tests: Acceptance data: . log: ../.Build/Web/typo3temp/var/tests/AcceptanceReports + output: ./.Build/Web/typo3temp/var/tests/_output support: Acceptance/Support settings: colors: true diff --git a/composer.json b/composer.json index 98a643d..9e71324 100644 --- a/composer.json +++ b/composer.json @@ -3,11 +3,17 @@ "description": "TYPO3 REST API Framework", "type": "typo3-cms-extension", "license": "GPL-3.0-or-later", + "repositories": [ + { + "type": "git", + "url": "https://github.com/toujou/tactician.git" + } + ], "require": { - "php": "^7.4 | ^8", + "php": "^8.1", "ext-json": "*", - "dfau/convergence": "dev-master", - "typo3/cms-core": "^11.5 | ^12.4", + "dfau/convergence": "v12.x-dev as dev-master", + "typo3/cms-core": "^12.4", "league/fractal": "~0.18", "league/tactician": "dev-master", "nikic/fast-route": "^1.3.0", @@ -20,11 +26,10 @@ "roave/security-advisories": "dev-latest", "dfau/coding-standard": "^2.0", "typo3/testing-framework": "^7.0.4", - "codeception/codeception": "^4.1", - "codeception/module-rest": "^1.3", - "codeception/module-asserts": "^1.3", - "codeception/module-phpbrowser": "^1.0", - "ssch/typo3-rector": "^v1.0.5" + "codeception/module-phpbrowser": "^3.0", + "codeception/module-asserts": "^3.0", + "codeception/module-rest": "^3.3", + "codeception/codeception": "^5.1" }, "authors": [ { diff --git a/etc/testing-docker/docker-compose.yml b/etc/testing-docker/docker-compose.yml index c21e8c5..945e0bf 100644 --- a/etc/testing-docker/docker-compose.yml +++ b/etc/testing-docker/docker-compose.yml @@ -230,9 +230,8 @@ services: done; echo Database is up; php -v | grep '^PHP'; - ln -sfn ${ROOT_DIR} Web/typo3conf/ext/toujou_api mkdir -p Web/typo3temp/var/tests/ - COMMAND=\"vendor/codeception/codeception/codecept run Api -d -c Web/typo3conf/ext/toujou_api/Tests/codeception.yml ${TEST_FILE}\" + COMMAND=\"vendor/codeception/codeception/codecept run Api -d -c ${ROOT_DIR}/Tests/codeception.yml ${TEST_FILE}\" if [ ${PHP_XDEBUG_ON} -eq 0 ]; then XDEBUG_MODE=\"off\" \ $${COMMAND};