From d05ada74ec631f64d196d1afc5b6bb7bfd6df6b0 Mon Sep 17 00:00:00 2001 From: Anja Leichsenring Date: Sun, 9 Oct 2022 12:00:37 +0200 Subject: [PATCH] [TASK] Replace prophecy calls in AdminPanelInitiatorTest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves: #98558 Releases: main, 11.5 Change-Id: Ic7bfd4812e49481f51603826a729423951275dbb Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/76034 Tested-by: core-ci Tested-by: Stefan Bürk Reviewed-by: Stefan Bürk --- .../Middleware/AdminPanelInitiatorTest.php | 65 +++++++------------ 1 file changed, 24 insertions(+), 41 deletions(-) diff --git a/typo3/sysext/adminpanel/Tests/Unit/Middleware/AdminPanelInitiatorTest.php b/typo3/sysext/adminpanel/Tests/Unit/Middleware/AdminPanelInitiatorTest.php index fa5030db0a8f..8e2326799584 100644 --- a/typo3/sysext/adminpanel/Tests/Unit/Middleware/AdminPanelInitiatorTest.php +++ b/typo3/sysext/adminpanel/Tests/Unit/Middleware/AdminPanelInitiatorTest.php @@ -17,9 +17,7 @@ namespace TYPO3\CMS\Adminpanel\Tests\Unit\Middleware; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; +use PHPUnit\Framework\MockObject\MockObject; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; @@ -34,8 +32,6 @@ */ class AdminPanelInitiatorTest extends UnitTestCase { - use ProphecyTrait; - /** * @var bool Reset singletons created by subject */ @@ -58,27 +54,20 @@ public function processCallsInitialize(): void 'display_top' => true, ], ]; - $userAuthenticationProphecy = $this->prophesize(FrontendBackendUserAuthentication::class); - $userAuthenticationProphecy->getTSConfig()->willReturn($tsConfig); - $userAuthentication = $userAuthenticationProphecy->reveal(); + $userAuthentication = $this->getMockBuilder(FrontendBackendUserAuthentication::class)->getMock(); + $userAuthentication->expects(self::once())->method('getTSConfig')->willReturn($tsConfig); $userAuthentication->uc = $uc; $GLOBALS['BE_USER'] = $userAuthentication; - $controller = $this->prophesize(MainController::class); - GeneralUtility::setSingletonInstance(MainController::class, $controller->reveal()); + $controller = $this->getMockBuilder(MainController::class)->disableOriginalConstructor()->getMock(); + GeneralUtility::setSingletonInstance(MainController::class, $controller); $handler = $this->prophesizeHandler(); - $request = $this->prophesize(ServerRequestInterface::class); - $request->withAttribute(Argument::cetera())->willReturn($request); - $controller->initialize($request->reveal())->willReturn($request); + $request = $this->getMockBuilder(ServerRequestInterface::class)->getMock(); + $request->expects(self::any())->method('withAttribute')->withAnyParameters()->willReturn($request); + $controller->expects(self::once())->method('initialize')->with($request)->willReturn($request); - // Act $adminPanelInitiator = new AdminPanelInitiator(); - $adminPanelInitiator->process( - $request->reveal(), - $handler->reveal() - ); - // Assert - $controller->initialize(Argument::any())->shouldHaveBeenCalled(); + $adminPanelInitiator->process($request, $handler); } /** @@ -123,37 +112,31 @@ public function processDoesNotCallInitializeIfNoAdminPanelModuleIsEnabled(): voi */ protected function checkAdminPanelDoesNotCallInitialize(array $tsConfig, array $uc): void { - $userAuthenticationProphecy = $this->prophesize(FrontendBackendUserAuthentication::class); - $userAuthenticationProphecy->getTSConfig()->willReturn($tsConfig); - $userAuthentication = $userAuthenticationProphecy->reveal(); + $userAuthentication = $this->getMockBuilder(FrontendBackendUserAuthentication::class)->getMock(); + $userAuthentication->expects(self::once())->method('getTSConfig')->willReturn($tsConfig); $userAuthentication->uc = $uc; $GLOBALS['BE_USER'] = $userAuthentication; - $controller = $this->prophesize(MainController::class); - GeneralUtility::setSingletonInstance(MainController::class, $controller->reveal()); + $controller = $this->getMockBuilder(MainController::class)->disableOriginalConstructor()->getMock(); + GeneralUtility::setSingletonInstance(MainController::class, $controller); $handler = $this->prophesizeHandler(); - $request = $this->prophesize(ServerRequestInterface::class); - // Act + $request = $this->getMockBuilder(ServerRequestInterface::class)->getMock(); + $adminPanelInitiator = new AdminPanelInitiator(); - $adminPanelInitiator->process( - $request->reveal(), - $handler->reveal() - ); - // Assert - $controller->initialize(Argument::any())->shouldNotHaveBeenCalled(); + $adminPanelInitiator->process($request, $handler); + + $controller->expects(self::never())->method('initialize'); } /** - * @return ObjectProphecy + * @return RequestHandlerInterface&MockObject */ - protected function prophesizeHandler(): ObjectProphecy + protected function prophesizeHandler(): MockObject { - $handler = $this->prophesize(RequestHandlerInterface::class); - $handler - ->handle(Argument::any()) - ->willReturn( - $this->prophesize(ResponseInterface::class)->reveal() - ); + $response = $this->getMockBuilder(ResponseInterface::class)->getMock(); + + $handler = $this->getMockBuilder(RequestHandlerInterface::class)->onlyMethods(['handle'])->getMock(); + $handler->expects(self::any())->method('handle')->withAnyParameters()->willReturn($response); return $handler; } }