@@ -121,7 +121,10 @@ public function testRouterDispatchesInternalRequests()
121121 $ this ->router ->get ('foo ' , function () { return 'bar ' ; });
122122 });
123123
124- $ this ->assertEquals ('{"message":"bar"} ' , $ this ->router ->dispatch (InternalRequest::create ('foo ' , 'GET ' ))->getContent ());
124+ $ request = InternalRequest::create ('foo ' , 'GET ' );
125+ $ request ->headers ->set ('accept ' , 'application/vnd.testing.v1+json ' );
126+
127+ $ this ->assertEquals ('{"message":"bar"} ' , $ this ->router ->dispatch ($ request )->getContent ());
125128 }
126129
127130
@@ -253,7 +256,10 @@ public function testRouterCatchesHttpExceptionsAndCreatesResponse()
253256 $ this ->router ->get ('foo ' , function () use ($ exception ) { throw $ exception ; });
254257 });
255258
256- $ response = $ this ->router ->dispatch (Request::create ('foo ' , 'GET ' ));
259+ $ request = Request::create ('foo ' , 'GET ' );
260+ $ request ->headers ->set ('accept ' , 'application/vnd.testing.v1+json ' );
261+
262+ $ response = $ this ->router ->dispatch ($ request );
257263
258264 $ this ->assertEquals (404 , $ response ->getStatusCode ());
259265 $ this ->assertEquals ('{"message":"404 Not Found"} ' , $ response ->getContent ());
@@ -355,4 +361,47 @@ public function testRequestTargettingAnApiWithNoPrefixOrDomain()
355361 }
356362
357363
364+ public function testRequestWithMultipleApisFindsTheCorrectApiRouteCollection ()
365+ {
366+ $ this ->router ->api (['version ' => 'v1 ' , 'prefix ' => 'api ' ], function ()
367+ {
368+ $ this ->router ->get ('foo ' , function () { return 'bar ' ; });
369+ });
370+
371+ $ this ->router ->api (['version ' => 'v2 ' , 'prefix ' => 'api ' ], function ()
372+ {
373+ $ this ->router ->get ('bar ' , function () { return 'baz ' ; });
374+ });
375+
376+ $ request = Request::create ('api/bar ' , 'GET ' );
377+ $ request ->headers ->set ('accept ' , 'application/vnd.testing.v2+json ' );
378+
379+ $ this ->assertEquals ('{"message":"baz"} ' , $ this ->router ->dispatch ($ request )->getContent ());
380+ }
381+
382+
383+ public function testApiCollectionsWithPointReleaseVersions ()
384+ {
385+ $ this ->router ->api (['version ' => 'v1.1 ' , 'prefix ' => 'api ' ], function ()
386+ {
387+ $ this ->router ->get ('foo ' , function () { return 'bar ' ; });
388+ });
389+
390+ $ this ->router ->api (['version ' => 'v2.0.1 ' , 'prefix ' => 'api ' ], function ()
391+ {
392+ $ this ->router ->get ('bar ' , function () { return 'baz ' ; });
393+ });
394+
395+ $ request = Request::create ('api/foo ' , 'GET ' );
396+ $ request ->headers ->set ('accept ' , 'application/vnd.testing.v1.1+json ' );
397+
398+ $ this ->assertEquals ('{"message":"bar"} ' , $ this ->router ->dispatch ($ request )->getContent ());
399+
400+ $ request = Request::create ('api/bar ' , 'GET ' );
401+ $ request ->headers ->set ('accept ' , 'application/vnd.testing.v2.0.1+json ' );
402+
403+ $ this ->assertEquals ('{"message":"baz"} ' , $ this ->router ->dispatch ($ request )->getContent ());
404+ }
405+
406+
358407}
0 commit comments