From 4b59fb99a770a479c1a16ddbaaab932f1f4b5912 Mon Sep 17 00:00:00 2001 From: shalvah Date: Thu, 1 Jul 2021 13:58:57 +0100 Subject: [PATCH] Fix tests --- .../Strategies/UrlParameters/GetFromLaravelAPI.php | 6 +++++- tests/Strategies/UrlParameters/GetFromLaravelAPITest.php | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Extracting/Strategies/UrlParameters/GetFromLaravelAPI.php b/src/Extracting/Strategies/UrlParameters/GetFromLaravelAPI.php index b56ea910..37563e0d 100644 --- a/src/Extracting/Strategies/UrlParameters/GetFromLaravelAPI.php +++ b/src/Extracting/Strategies/UrlParameters/GetFromLaravelAPI.php @@ -29,7 +29,11 @@ public function __invoke(ExtractedEndpointData $endpointData, array $routeRules) $name = rtrim($match, '?'); // In case of /users/{user:id}, make the param {user}, but - $binding = $endpointData->route->bindingFieldFor($name); + $binding = null; + // Was added in Laravel 7.x + if (method_exists($endpointData->route, 'bindingFieldFor')) { + $binding = $endpointData->route->bindingFieldFor($name); + } $parameters[$name] = [ 'name' => $name, 'description' => $this->inferUrlParamDescription($endpointData->uri, $binding ?: $name, $binding ? $name : null), diff --git a/tests/Strategies/UrlParameters/GetFromLaravelAPITest.php b/tests/Strategies/UrlParameters/GetFromLaravelAPITest.php index 909491a0..2ddb45ad 100644 --- a/tests/Strategies/UrlParameters/GetFromLaravelAPITest.php +++ b/tests/Strategies/UrlParameters/GetFromLaravelAPITest.php @@ -103,6 +103,12 @@ public function __construct(array $parameters = []) /** @test */ public function can_infer_data_from_field_bindings() { + if (version_compare($this->app->version(), '7.0.0', '<')) { + $this->markTestSkipped("Laravel < 7.x doesn't support field binding syntax."); + + return; + } + $strategy = new GetFromLaravelAPI(new DocumentationConfig([])); $endpoint = new class extends ExtractedEndpointData {