Zend\Stratigility\Middleware\NotFoundHandler::process PHP Method

process() public method

Creates and returns a 404 response.
public process ( Psr\Http\Message\ServerRequestInterface $request, Interop\Http\Middleware\DelegateInterface $delegate ) : Psr\Http\Message\ResponseInterface
$request Psr\Http\Message\ServerRequestInterface Ignored.
$delegate Interop\Http\Middleware\DelegateInterface Ignored.
return Psr\Http\Message\ResponseInterface
    public function process(ServerRequestInterface $request, DelegateInterface $delegate)
    {
        $response = $this->responsePrototype->withStatus(404);
        $response->getBody()->write(sprintf("Cannot %s %s", $request->getMethod(), (string) $request->getUri()));
        return $response;
    }

Usage Example

 public function testReturnsResponseWith404StatusAndErrorMessageInBody()
 {
     $stream = $this->prophesize(StreamInterface::class);
     $stream->write('Cannot POST https://example.com/foo');
     $response = $this->prophesize(ResponseInterface::class);
     $response->withStatus(404)->will([$response, 'reveal']);
     $response->getBody()->will([$stream, 'reveal']);
     $request = $this->prophesize(ServerRequestInterface::class);
     $request->getMethod()->willReturn('POST');
     $request->getUri()->willReturn('https://example.com/foo');
     $middleware = new NotFoundHandler($response->reveal());
     $this->assertSame($response->reveal(), $middleware->process($request->reveal(), $this->prophesize(DelegateInterface::class)->reveal()));
 }