|
@@ -6,6 +6,7 @@ use Illuminate\Routing\Route as LaravelRoute;
|
|
|
use Illuminate\Support\Facades\Route;
|
|
|
use Knuckles\Camel\Extraction\ExtractedEndpointData;
|
|
|
use Knuckles\Scribe\Matching\RouteMatcher;
|
|
|
+use Knuckles\Scribe\Scribe;
|
|
|
use Knuckles\Scribe\Tests\BaseLaravelTest;
|
|
|
use Knuckles\Scribe\Tests\Fixtures\TestController;
|
|
|
|
|
@@ -28,6 +29,28 @@ class ExtractedEndpointDataTest extends BaseLaravelTest
|
|
|
$this->assertEquals('things/{thing_id}/otherthings/{id}', $this->expectedUri($route));
|
|
|
}
|
|
|
|
|
|
+ /** @test */
|
|
|
+ public function allows_user_specified_normalization()
|
|
|
+ {
|
|
|
+ Scribe::normalizeEndpointUrlUsing(function (string $url, LaravelRoute $route, \ReflectionFunctionAbstract $method, ?\ReflectionClass $controller) {
|
|
|
+ if ($url == 'things/{thing}') return 'things/{the_id_of_the_thing}';
|
|
|
+
|
|
|
+ if ($route->named('things.otherthings.destroy')) return 'things/{thing-id}/otherthings/{other_thing-id}';
|
|
|
+ });
|
|
|
+
|
|
|
+ Route::apiResource('things', TestController::class)->only('show');
|
|
|
+ $route = $this->getRoute(['prefixes' => '*']);
|
|
|
+ $this->assertEquals('things/{thing}', $this->originalUri($route));
|
|
|
+ $this->assertEquals('things/{the_id_of_the_thing}', $this->expectedUri($route));
|
|
|
+
|
|
|
+ Route::apiResource('things.otherthings', TestController::class)->only('destroy');
|
|
|
+ $route = $this->getRoute(['prefixes' => '*/otherthings/*']);
|
|
|
+ $this->assertEquals('things/{thing}/otherthings/{otherthing}', $this->originalUri($route));
|
|
|
+ $this->assertEquals('things/{thing-id}/otherthings/{other_thing-id}', $this->expectedUri($route));
|
|
|
+
|
|
|
+ Scribe::normalizeEndpointUrlUsing(null);
|
|
|
+ }
|
|
|
+
|
|
|
/** @test */
|
|
|
public function normalizes_resource_url_params_from_underscores_to_hyphens()
|
|
|
{
|