middleware = new PathVersionMiddleware(); } /** * @test */ public function whenVersionIsProvidedRequestRemainsUnchanged() { $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/v2/foo')); $test = $this; $this->middleware->__invoke($request, new Response(), function ($req) use ($request, $test) { $test->assertSame($request, $req); }); } /** * @test */ public function versionOneIsPrependedWhenNoVersionIsDefined() { $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/bar/baz')); $test = $this; $this->middleware->__invoke($request, new Response(), function (Request $req) use ($request, $test) { $test->assertNotSame($request, $req); $this->assertEquals('/rest/v1/bar/baz', $req->getUri()->getPath()); }); } }