ExtractedEndpointDataTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Knuckles\Scribe\Tests\Unit;
  3. use Illuminate\Support\Facades\Route;
  4. use Knuckles\Camel\Extraction\ExtractedEndpointData;
  5. use Knuckles\Scribe\Matching\RouteMatcher;
  6. use Knuckles\Scribe\Tests\BaseLaravelTest;
  7. use Knuckles\Scribe\Tests\Fixtures\TestController;
  8. class ExtractedEndpointDataTest extends BaseLaravelTest
  9. {
  10. /** @test */
  11. public function will_normalize_resource_url_params()
  12. {
  13. Route::apiResource('things', TestController::class)
  14. ->only('show');
  15. $routeRules[0]['match'] = ['prefixes' => '*', 'domains' => '*'];
  16. $matcher = new RouteMatcher();
  17. $matchedRoutes = $matcher->getRoutes($routeRules);
  18. foreach ($matchedRoutes as $matchedRoute) {
  19. $route = $matchedRoute->getRoute();
  20. $this->assertEquals('things/{thing}', $route->uri);
  21. $endpoint = new ExtractedEndpointData([
  22. 'route' => $route,
  23. 'uri' => $route->uri,
  24. 'httpMethods' => $route->methods,
  25. ]);
  26. $this->assertEquals('things/{id}', $endpoint->uri);
  27. }
  28. Route::apiResource('things.otherthings', TestController::class)
  29. ->only( 'destroy');
  30. $routeRules[0]['match'] = ['prefixes' => '*/otherthings/*', 'domains' => '*'];
  31. $matchedRoutes = $matcher->getRoutes($routeRules);
  32. foreach ($matchedRoutes as $matchedRoute) {
  33. $route = $matchedRoute->getRoute();
  34. $this->assertEquals('things/{thing}/otherthings/{otherthing}', $route->uri);
  35. $endpoint = new ExtractedEndpointData([
  36. 'route' => $route,
  37. 'uri' => $route->uri,
  38. 'httpMethods' => $route->methods,
  39. ]);
  40. $this->assertEquals('things/{id}/otherthings/{otherthing_id}', $endpoint->uri);
  41. }
  42. }
  43. }