From d3c7af4c61cf7915fe588efd668bde1e6ce3b563 Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Tue, 18 Mar 2025 08:38:24 -0700 Subject: [PATCH] Fixed broken tests --- tests/Bootstrap/MiddlewareManagerTest.php | 12 +++++++----- tests/Middlewares/WhoopsMiddlewareTest.php | 9 ++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/Bootstrap/MiddlewareManagerTest.php b/tests/Bootstrap/MiddlewareManagerTest.php index 5fa87ee..e3fae84 100644 --- a/tests/Bootstrap/MiddlewareManagerTest.php +++ b/tests/Bootstrap/MiddlewareManagerTest.php @@ -25,12 +25,14 @@ class MiddlewareManagerTest extends TestCase #[Test] public function it_registers_application_middlewares(): void { - $arguments = array_map(static function (string $middleware): array { - return [$middleware]; - }, self::MIDDLEWARES); - $app = $this->createMock(App::class); - $app->expects($this->atLeast(1))->method('add')->withConsecutive(...$arguments); + $app->expects($matcher = $this->atLeast(1))->method('add')->willReturnCallback( + function ($parameter) use ($matcher, $app): App { + $this->assertSame(self::MIDDLEWARES[$matcher->numberOfInvocations() - 1], $parameter); + + return $app; + } + ); (new MiddlewareManager($app, $this->config))(); } diff --git a/tests/Middlewares/WhoopsMiddlewareTest.php b/tests/Middlewares/WhoopsMiddlewareTest.php index d12a3a8..ccefee9 100644 --- a/tests/Middlewares/WhoopsMiddlewareTest.php +++ b/tests/Middlewares/WhoopsMiddlewareTest.php @@ -10,6 +10,7 @@ use PHPUnit\Framework\Attributes\Test; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use Tests\TestCase; +use Whoops\Handler\Handler; use Whoops\Handler\JsonResponseHandler; use Whoops\Handler\PrettyPageHandler; use Whoops\RunInterface; @@ -57,9 +58,11 @@ class WhoopsMiddlewareTest extends TestCase $jsonHandler = new JsonResponseHandler; $whoops = $this->createMock(RunInterface::class); - $whoops->expects($this->exactly(2))->method('pushHandler')->withConsecutive( - [$pageHandler], - [$jsonHandler] + $whoops->expects($matcher = $this->exactly(2))->method('pushHandler')->willReturnCallback( + fn (Handler $parameter) => match ($matcher->numberOfInvocations()) { + 1 => $this->assertSame($pageHandler, $parameter), + 2 => $this->assertSame($jsonHandler, $parameter), + } ); $middleware = new WhoopsMiddleware($whoops, $pageHandler, $jsonHandler);