From 29319fd26fcaf94c352634e00de97a3dfafc9c81 Mon Sep 17 00:00:00 2001 From: Christian Kuhn Date: Mon, 3 Apr 2023 15:57:32 +0200 Subject: [PATCH] [TASK] Avoid withConsecutive() in RequestHandlerTest Even though the RequestHandlerTest unit tests are an aweful mocking party, we can't simply throw them away since the class is so important. They should still be turned into functional tests later, to be more useful, maybe together with a refactoring of that class. The patch just changes the tests to avoid withConsecutive(), which does not improve the situation, but a bigger refactoring is currently a bit too much with our current goal of "just" adding phpunit 10 compatibility. Resolves: #100410 Related: #100249 Releases: main Change-Id: I8b09013b826ed56e0c6e96eade4c9f4a61346273 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/78379 Tested-by: core-ci Reviewed-by: Oliver Bartsch Tested-by: Andreas Fernandez Reviewed-by: Oliver Klee Tested-by: Oliver Klee Tested-by: Oliver Bartsch Reviewed-by: Andreas Fernandez --- .../Tests/Unit/Http/RequestHandlerTest.php | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/typo3/sysext/frontend/Tests/Unit/Http/RequestHandlerTest.php b/typo3/sysext/frontend/Tests/Unit/Http/RequestHandlerTest.php index e6b5060ca8a2..02f1b7c8ad47 100644 --- a/typo3/sysext/frontend/Tests/Unit/Http/RequestHandlerTest.php +++ b/typo3/sysext/frontend/Tests/Unit/Http/RequestHandlerTest.php @@ -35,6 +35,9 @@ use TYPO3\CMS\Frontend\Http\RequestHandler; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; +/** + * @todo: It looks as if these unit tests should be turned into functional tests + */ class RequestHandlerTest extends UnitTestCase { protected bool $resetSingletonInstances = true; @@ -449,10 +452,21 @@ public function generateMultipleMetaTags(array $typoScript, string $stdWrapResul $pageRendererMock = $this->getMockBuilder(PageRenderer::class)->disableOriginalConstructor()->getMock(); $pageRendererMock->method('getDocType')->willReturn(DocType::html5); - $pageRendererMock->expects(self::exactly(2))->method('setMetaTag')->withConsecutive( + $series = [ [$expectedTags[0]['type'], $expectedTags[0]['name'], $expectedTags[0]['content'], [], false], - [$expectedTags[1]['type'], $expectedTags[1]['name'], $expectedTags[1]['content'], [], false] - ); + [$expectedTags[1]['type'], $expectedTags[1]['name'], $expectedTags[1]['content'], [], false], + ]; + $pageRendererMock + ->expects(self::exactly(2)) + ->method('setMetaTag') + ->willReturnCallback(function (string $type, string $name, string $content, array $subProperties, bool $replace) use (&$series): void { + $expectedArgs = array_shift($series); + self::assertSame($expectedArgs[0], $type); + self::assertSame($expectedArgs[1], $name); + self::assertSame($expectedArgs[2], $content); + self::assertSame($expectedArgs[3], $subProperties); + self::assertSame($expectedArgs[4], $replace); + }); $frontendTypoScript = new FrontendTypoScript(new RootNode(), []); $frontendTypoScript->setSetupArray([]); $request = (new ServerRequest())->withAttribute('frontend.typoscript', $frontendTypoScript);