Fixed broken tests

This commit is contained in:
Chris Kankiewicz
2025-03-18 08:38:24 -07:00
parent 412221f3fb
commit d3c7af4c61
2 changed files with 13 additions and 8 deletions

View File

@@ -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))();
}

View File

@@ -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);