middleware = new PathVersionMiddleware(); } /** * @test */ public function whenVersionIsProvidedRequestRemainsUnchanged() { $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/v2/foo')); $delegate = $this->prophesize(RequestHandlerInterface::class); $process = $delegate->handle($request)->willReturn(new Response()); $this->middleware->process($request, $delegate->reveal()); $process->shouldHaveBeenCalled(); } /** * @test */ public function versionOneIsPrependedWhenNoVersionIsDefined() { $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/bar/baz')); $delegate = $this->prophesize(RequestHandlerInterface::class); $delegate->handle(Argument::type(Request::class))->will(function (array $args) use ($request) { $req = array_shift($args); Assert::assertNotSame($request, $req); Assert::assertEquals('/v1/bar/baz', $req->getUri()->getPath()); return new Response(); }); $this->middleware->process($request, $delegate->reveal()); } }