handler = $this->createMock(RequestHandlerInterface::class); $this->requestTracker = $this->createMock(RequestTrackerInterface::class); $this->middleware = new NotFoundTrackerMiddleware($this->requestTracker); $this->request = ServerRequestFactory::fromGlobals()->withAttribute( NotFoundType::class, $this->createMock(NotFoundType::class), ); } #[Test, DataProvider('provideResponses')] public function delegatesIntoRequestTracker(Response $resp, string|null $expectedRedirectUrl): void { $this->handler->expects($this->once())->method('handle')->with($this->request)->willReturn($resp); $this->requestTracker->expects($this->once())->method('trackNotFoundIfApplicable')->with( $this->request->withAttribute(REDIRECT_URL_REQUEST_ATTRIBUTE, $expectedRedirectUrl), ); $result = $this->middleware->process($this->request, $this->handler); self::assertSame($resp, $result); } public static function provideResponses(): iterable { yield 'no location response' => [new Response(), null]; yield 'location response' => [new Response\RedirectResponse('the_location'), 'the_location']; } }