middleware = new ShortCodePathMiddleware(); $this->requestHandler = $this->prophesize(RequestHandlerInterface::class); $this->requestHandler->handle(Argument::type(ServerRequestInterface::class))->willReturn(new Response()); } /** @test */ public function properlyReplacesTheOldPathByTheNewOne() { $uri = new Uri('/short-codes/foo'); $request = $this->prophesize(ServerRequestInterface::class); $request->getUri()->willReturn($uri); $withUri = $request->withUri(Argument::that(function (UriInterface $uri) { $path = $uri->getPath(); Assert::assertStringContainsString('/short-urls', $path); Assert::assertStringNotContainsString('/short-codes', $path); return $uri; }))->willReturn($request->reveal()); $this->middleware->process($request->reveal(), $this->requestHandler->reveal()); $withUri->shouldHaveBeenCalledOnce(); } }