From 52b39e065d68cfcd514fceab719e61bd80ce3965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Fri, 29 Mar 2024 14:16:20 -0300 Subject: [PATCH] Reset ResponseRenderer::$instance after test in ApplicationHandlerTest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not resetting this value causes other tests to fail when running then in a specific order. Signed-off-by: MaurĂ­cio Meneghini Fauth --- .../unit/Http/Handler/ApplicationHandlerTest.php | 16 +++++++++------- tests/unit/Stubs/ResponseRenderer.php | 6 ------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/tests/unit/Http/Handler/ApplicationHandlerTest.php b/tests/unit/Http/Handler/ApplicationHandlerTest.php index 51e2d60799..698f7fe293 100644 --- a/tests/unit/Http/Handler/ApplicationHandlerTest.php +++ b/tests/unit/Http/Handler/ApplicationHandlerTest.php @@ -10,7 +10,6 @@ use PhpMyAdmin\Http\Handler\ApplicationHandler; use PhpMyAdmin\Http\Response; use PhpMyAdmin\Http\ServerRequest; use PhpMyAdmin\ResponseRenderer; -use PHPUnit\Framework\Attributes\BackupStaticProperties; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseInterface; @@ -19,12 +18,12 @@ use ReflectionProperty; #[CoversClass(ApplicationHandler::class)] final class ApplicationHandlerTest extends TestCase { - #[BackupStaticProperties(true)] public function testHandleReturnsResponse(): void { $responseRendererMock = self::createMock(ResponseRenderer::class); $responseRendererMock->expects(self::never())->method('response'); - (new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, $responseRendererMock); + $reflectionProperty = new ReflectionProperty(ResponseRenderer::class, 'instance'); + $reflectionProperty->setValue(null, $responseRendererMock); $request = self::createStub(ServerRequest::class); $responseStub = new Response(self::createStub(ResponseInterface::class)); $appMock = self::createMock(Application::class); @@ -32,35 +31,38 @@ final class ApplicationHandlerTest extends TestCase $handler = new ApplicationHandler($appMock); $response = $handler->handle($request); self::assertSame($response, $responseStub); + $reflectionProperty->setValue(null, null); } - #[BackupStaticProperties(true)] public function testHandleThrowsExit(): void { $responseStub = new Response(self::createStub(ResponseInterface::class)); $responseRendererMock = self::createMock(ResponseRenderer::class); $responseRendererMock->expects(self::once())->method('response')->willReturn($responseStub); - (new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, $responseRendererMock); + $reflectionProperty = new ReflectionProperty(ResponseRenderer::class, 'instance'); + $reflectionProperty->setValue(null, $responseRendererMock); $request = self::createStub(ServerRequest::class); $appMock = self::createMock(Application::class); $appMock->expects(self::once())->method('handle')->with($request)->willThrowException(new ExitException()); $handler = new ApplicationHandler($appMock); $response = $handler->handle($request); self::assertSame($response, $responseStub); + $reflectionProperty->setValue(null, null); } - #[BackupStaticProperties(true)] public function testHandleReturnsNull(): void { $responseStub = new Response(self::createStub(ResponseInterface::class)); $responseRendererMock = self::createMock(ResponseRenderer::class); $responseRendererMock->expects(self::once())->method('response')->willReturn($responseStub); - (new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, $responseRendererMock); + $reflectionProperty = new ReflectionProperty(ResponseRenderer::class, 'instance'); + $reflectionProperty->setValue(null, $responseRendererMock); $request = self::createStub(ServerRequest::class); $appMock = self::createMock(Application::class); $appMock->expects(self::once())->method('handle')->with($request)->willReturn(null); $handler = new ApplicationHandler($appMock); $response = $handler->handle($request); self::assertSame($response, $responseStub); + $reflectionProperty->setValue(null, null); } } diff --git a/tests/unit/Stubs/ResponseRenderer.php b/tests/unit/Stubs/ResponseRenderer.php index 1faab2d41a..0736e0a16b 100644 --- a/tests/unit/Stubs/ResponseRenderer.php +++ b/tests/unit/Stubs/ResponseRenderer.php @@ -16,7 +16,6 @@ use PhpMyAdmin\Config; use PhpMyAdmin\ConfigStorage\Relation; use PhpMyAdmin\Console; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Exceptions\ExitException; use PhpMyAdmin\Footer; use PhpMyAdmin\Header; use PhpMyAdmin\Http\Factory\ResponseFactory; @@ -177,11 +176,6 @@ class ResponseRenderer extends \PhpMyAdmin\ResponseRenderer return $this->isDisabled; } - public function callExit(string $message = ''): never - { - throw new ExitException($message); - } - public function getResponse(): Response { return $this->response;