Zolotov Alexander 6 anni fa
parent
commit
0b1d43cdbf

+ 29 - 0
tests/GenerateDocumentationTest.php

@@ -93,6 +93,35 @@ class GenerateDocumentationTest extends TestCase
         $this->assertContains('Processed route: [GET] test', $output);
     }
 
+    /** @test */
+    public function console_command_work_with_rotes_uses_array()
+    {
+        RouteFacade::get('/api/test', [TestController::class, 'withEndpointDescription']);
+
+        config(['apidoc.routes.0.match.prefixes' => ['api/*']]);
+        $output = $this->artisan('apidoc:generate');
+
+        $this->assertNotContains('Skipping route: [GET] test', $output);
+        $this->assertContains('Processed route: [GET] test', $output);
+    }
+
+    /** @test */
+    public function console_command_work_with_dingo_rotes_uses_array()
+    {
+        $api = app(\Dingo\Api\Routing\Router::class);
+        $api->version('v1', function ($api) {
+            $api->get('/test', [TestController::class, 'withEndpointDescription']);
+        });
+
+        config(['apidoc.router' => 'dingo']);
+        config(['apidoc.routes.0.match.prefixes' => ['*']]);
+        config(['apidoc.routes.0.match.versions' => ['v1']]);
+        $output = $this->artisan('apidoc:generate');
+
+        $this->assertNotContains('Skipping route: [GET] test', $output);
+        $this->assertContains('Processed route: [GET] test', $output);
+    }
+
     /** @test */
     public function can_skip_single_routes()
     {

+ 12 - 0
tests/Unit/DingoGeneratorTest.php

@@ -34,4 +34,16 @@ class DingoGeneratorTest extends GeneratorTestCase
 
         return $route;
     }
+
+    public function createRouteUsesArray(string $httpMethod, string $path, string $controllerMethod, $register = false)
+    {
+        $route = null;
+        /** @var Router $api */
+        $api = app(Router::class);
+        $api->version('v1', function (Router $api) use ($controllerMethod, $path, $httpMethod, &$route) {
+            $route = $api->$httpMethod($path, [TestController::class, $controllerMethod]);
+        });
+
+        return $route;
+    }
 }

+ 13 - 0
tests/Unit/GeneratorTestCase.php

@@ -600,5 +600,18 @@ abstract class GeneratorTestCase extends TestCase
         $this->assertEquals('value', $responseContent['header']);
     }
 
+    /** @test */
+    public function can_use_arrays_in_routes_uses()
+    {
+        $route = $this->createRoute('GET', '/api/test', 'withEndpointDescription');
+        $parsed = $this->generator->processRoute($route)['group'];
+
+        $this->assertSame('Group A', $parsed['group']);
+        $this->assertSame('Example title.', $parsed['title']);
+        $this->assertSame("This will be the long description.\nIt can also be multiple lines long.", $parsed['description']);
+    }
+
     abstract public function createRoute(string $httpMethod, string $path, string $controllerMethod, $register = false);
+
+    abstract public function createRouteUsesArray(string $httpMethod, string $path, string $controllerMethod, $register = false);
 }

+ 9 - 0
tests/Unit/LaravelGeneratorTest.php

@@ -24,4 +24,13 @@ class LaravelGeneratorTest extends GeneratorTestCase
             return new Route([$httpMethod], $path, ['uses' => TestController::class."@$controllerMethod"]);
         }
     }
+
+    public function createRouteUsesArray(string $httpMethod, string $path, string $controllerMethod, $register = false)
+    {
+        if ($register) {
+            return RouteFacade::{$httpMethod}($path, TestController::class."@$controllerMethod");
+        } else {
+            return new Route([$httpMethod], $path, ['uses' => [TestController::class, $controllerMethod]]);
+        }
+    }
 }