diff --git a/.travis.yml b/.travis.yml index 2087b8c..4ca8a3d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,9 @@ matrix: - php: 7.4 env: SETUP=lint name: "Lint code" + - php: 7.4 + env: COMPOSER=dingo.composer.json + name: "With Dingo router" cache: directories: @@ -34,4 +37,4 @@ install: - if [[ $SETUP = 'lint' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable --no-suggest; travis_retry composer lint; fi script: - - vendor/bin/phpunit + - if [[ $SETUP = 'lint' ]]; then exit 0; fi; composer test-ci; diff --git a/composer.json b/composer.json index bbe37f7..5f4ce3b 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,6 @@ "symfony/var-exporter": "^4.0|^5.0" }, "require-dev": { - "dingo/api": "^2.7|^3.0", "dms/phpunit-arraysubset-asserts": "^0.1.0", "laravel/lumen-framework": "^5.7|^6.0|^7.0", "league/fractal": "^0.19.0", @@ -53,8 +52,8 @@ }, "scripts": { "lint": "phpstan analyse -c ./phpstan.neon src", - "test": "phpunit --stop-on-failure", - "test-ci": "phpunit" + "test": "phpunit --stop-on-failure --exclude-group dingo", + "test-ci": "phpunit --exclude-group dingo" }, "extra": { "laravel": { diff --git a/dingo.composer.json b/dingo.composer.json new file mode 100644 index 0000000..2e03661 --- /dev/null +++ b/dingo.composer.json @@ -0,0 +1,72 @@ +{ + "name": "mpociot/laravel-apidoc-generator", + "license": "MIT", + "description": "Generate beautiful API documentation from your Laravel application", + "keywords": [ + "API", + "Documentation", + "Laravel" + ], + "homepage": "http://github.com/mpociot/laravel-apidoc-generator", + "authors": [ + { + "name": "Marcel Pociot", + "email": "m.pociot@gmail.com" + } + ], + "require": { + "php": ">=7.2.0", + "ext-json": "*", + "fzaninotto/faker": "^1.8", + "illuminate/console": "^5.7|^6.0|^7.0", + "illuminate/routing": "^5.7|^6.0|^7.0", + "illuminate/support": "^5.7|^6.0|^7.0", + "league/flysystem": "^1.0", + "mpociot/documentarian": "^0.4.0", + "mpociot/reflection-docblock": "^1.0.1", + "nunomaduro/collision": "^3.0|^4.0", + "ramsey/uuid": "^3.8|4.0", + "symfony/var-exporter": "^4.0|^5.0" + }, + "require-dev": { + "dingo/api": "^2.7|^3.0", + "dms/phpunit-arraysubset-asserts": "^0.1.0", + "league/fractal": "^0.19.0", + "mockery/mockery": "^1.2.0", + "orchestra/testbench": "^3.7|^4.0|^5.0", + "phpstan/phpstan": "^0.11.15", + "phpunit/phpunit": "^8.0" + }, + "suggest": { + "league/fractal": "Required for transformers support" + }, + "autoload": { + "psr-4": { + "Mpociot\\ApiDoc\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Mpociot\\ApiDoc\\Tests\\": "tests/" + } + }, + "scripts": { + "lint": "phpstan analyse -c ./phpstan.neon src", + "test": "phpunit --stop-on-failure", + "test-ci": "phpunit" + }, + "extra": { + "laravel": { + "providers": [ + "Mpociot\\ApiDoc\\ApiDocGeneratorServiceProvider" + ] + }, + "branch-alias": { + "dev-v4": "4.x-dev" + } + }, + "config": { + "preferred-install": "dist", + "sort-packages": true + } +} diff --git a/tests/Fixtures/TestNonCommentedRequest.php b/tests/Fixtures/TestNonCommentedRequest.php index 837f8ee..18ada51 100644 --- a/tests/Fixtures/TestNonCommentedRequest.php +++ b/tests/Fixtures/TestNonCommentedRequest.php @@ -2,7 +2,7 @@ namespace Mpociot\ApiDoc\Tests\Fixtures; -use Dingo\Api\Http\FormRequest; +use Illuminate\Foundation\Http\FormRequest; class TestNonCommentedRequest extends FormRequest { diff --git a/tests/Fixtures/TestRequest.php b/tests/Fixtures/TestRequest.php index 5b11ccd..4847e42 100644 --- a/tests/Fixtures/TestRequest.php +++ b/tests/Fixtures/TestRequest.php @@ -2,7 +2,7 @@ namespace Mpociot\ApiDoc\Tests\Fixtures; -use Dingo\Api\Http\FormRequest; +use Illuminate\Foundation\Http\FormRequest; /** * @bodyParam user_id int required The id of the user. Example: 9 diff --git a/tests/GenerateDocumentationTest.php b/tests/GenerateDocumentationTest.php index 5338f2e..595dda8 100644 --- a/tests/GenerateDocumentationTest.php +++ b/tests/GenerateDocumentationTest.php @@ -49,7 +49,6 @@ class GenerateDocumentationTest extends TestCase protected function getPackageProviders($app) { return [ - \Dingo\Api\Provider\LaravelServiceProvider::class, ApiDocGeneratorServiceProvider::class, ]; } @@ -69,26 +68,6 @@ class GenerateDocumentationTest extends TestCase $this->assertStringContainsString('Processed route: [GET] api/test', $output); } - /** @test */ - public function console_command_does_not_work_with_closure_using_dingo() - { - $api = app(\Dingo\Api\Routing\Router::class); - $api->version('v1', function ($api) { - $api->get('/closure', function () { - return 'foo'; - }); - $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->assertStringContainsString('Skipping route: [GET] closure', $output); - $this->assertStringContainsString('Processed route: [GET] test', $output); - } - /** @test */ public function console_command_works_with_routes_callable_tuple() { diff --git a/tests/Unit/DingoGeneratorTest.php b/tests/Unit/DingoGeneratorTest.php index 74211c5..e9d690c 100644 --- a/tests/Unit/DingoGeneratorTest.php +++ b/tests/Unit/DingoGeneratorTest.php @@ -6,6 +6,9 @@ use Dingo\Api\Routing\Router; use Mpociot\ApiDoc\ApiDocGeneratorServiceProvider; use Mpociot\ApiDoc\Tests\Fixtures\TestController; +/** + * @group dingo + */ class DingoGeneratorTest extends GeneratorTestCase { protected function getPackageProviders($app) diff --git a/tests/Unit/RouteMatcherDingoTest.php b/tests/Unit/RouteMatcherDingoTest.php new file mode 100644 index 0000000..a40035e --- /dev/null +++ b/tests/Unit/RouteMatcherDingoTest.php @@ -0,0 +1,326 @@ +registerDingoRoutes(); + $routeRules[0]['match']['versions'] = ['v1']; + $routeRules[0]['match']['prefixes'] = ['*']; + + $routeRules[0]['match']['domains'] = ['*']; + $matcher = new RouteMatcher(); + $routes = $matcher->getRoutes($routeRules, 'dingo'); + $this->assertCount(12, $routes); + + $routeRules[0]['match']['domains'] = ['domain1.*', 'domain2.*']; + $matcher = new RouteMatcher(); + $routes = $matcher->getRoutes($routeRules, 'dingo'); + $this->assertCount(12, $routes); + + $routeRules[0]['match']['domains'] = ['domain1.*']; + $matcher = new RouteMatcher(); + $routes = $matcher->getRoutes($routeRules, 'dingo'); + $this->assertCount(6, $routes); + foreach ($routes as $route) { + $this->assertStringContainsString('domain1', $route['route']->getDomain()); + } + + $routeRules[0]['match']['domains'] = ['domain2.*']; + $matcher = new RouteMatcher(); + $routes = $matcher->getRoutes($routeRules, 'dingo'); + $this->assertCount(6, $routes); + foreach ($routes as $route) { + $this->assertStringContainsString('domain2', $route['route']->getDomain()); + } + } + + public function testRespectsPrefixesRuleForDingoRouter() + { + $this->registerDingoRoutes(); + $routeRules[0]['match']['versions'] = ['v1']; + $routeRules[0]['match']['domains'] = ['*']; + + $routeRules[0]['match']['prefixes'] = ['*']; + $matcher = new RouteMatcher(); + $routes = $matcher->getRoutes($routeRules, 'dingo'); + $this->assertCount(12, $routes); + + $routeRules[0]['match']['prefixes'] = ['prefix1/*', 'prefix2/*']; + $matcher = new RouteMatcher(); + $routes = $matcher->getRoutes($routeRules, 'dingo'); + $this->assertCount(8, $routes); + + $routeRules[0]['match']['prefixes'] = ['prefix1/*']; + $matcher = new RouteMatcher(); + $routes = $matcher->getRoutes($routeRules, 'dingo'); + $this->assertCount(4, $routes); + foreach ($routes as $route) { + $this->assertTrue(Str::is('prefix1/*', $route['route']->uri())); + } + + $routeRules[0]['match']['prefixes'] = ['prefix2/*']; + $matcher = new RouteMatcher(); + $routes = $matcher->getRoutes($routeRules, 'dingo'); + $this->assertCount(4, $routes); + foreach ($routes as $route) { + $this->assertTrue(Str::is('prefix2/*', $route['route']->uri())); + } + } + + public function testRespectsVersionsRuleForDingoRouter() + { + $this->registerDingoRoutes(); + + $routeRules[0]['match']['versions'] = ['v2']; + $routeRules[0]['match']['domains'] = ['*']; + $routeRules[0]['match']['prefixes'] = ['*']; + $matcher = new RouteMatcher(); + $routes = $matcher->getRoutes($routeRules, 'dingo'); + $this->assertCount(6, $routes); + foreach ($routes as $route) { + $this->assertNotEmpty(array_intersect($route['route']->versions(), ['v2'])); + } + + $routeRules[0]['match']['versions'] = ['v1', 'v2']; + $routeRules[0]['match']['domains'] = ['*']; + $routeRules[0]['match']['prefixes'] = ['*']; + $matcher = new RouteMatcher(); + $routes = $matcher->getRoutes($routeRules, 'dingo'); + $this->assertCount(18, $routes); + } + + public function testWillIncludeRouteIfListedExplicitlyForLaravelRouter() + { + $this->registerLaravelRoutes(); + $mustInclude = 'domain1-1'; + $routeRules[0]['include'] = [$mustInclude]; + + $routeRules[0]['match']['domains'] = ['domain1.*']; + $routeRules[0]['match']['prefixes'] = ['prefix1/*']; + $matcher = new RouteMatcher(); + $routes = $matcher->getRoutes($routeRules); + $oddRuleOut = collect($routes)->filter(function ($route) use ($mustInclude) { + return $route['route']->getName() === $mustInclude; + }); + $this->assertCount(1, $oddRuleOut); + } + + public function testWillIncludeRouteIfListedExplicitlyForDingoRouter() + { + $this->registerDingoRoutes(); + + $mustInclude = 'v2.domain2'; + $routeRules = [ + [ + 'match' => [ + 'domains' => ['domain1.*'], + 'prefixes' => ['prefix1/*'], + 'versions' => ['v1'], + ], + 'include' => [$mustInclude], + ], + ]; + $matcher = new RouteMatcher(); + $routes = $matcher->getRoutes($routeRules, 'dingo'); + $oddRuleOut = collect($routes)->filter(function ($route) use ($mustInclude) { + return $route['route']->getName() === $mustInclude; + }); + $this->assertCount(1, $oddRuleOut); + } + + public function testWillIncludeRouteIfMatchForAnIncludePatternForDingoRouter() + { + $this->registerDingoRoutes(); + + $mustInclude = ['v2.domain1', 'v2.domain2']; + $includePattern = 'v2.domain*'; + $routeRules = [ + [ + 'match' => [ + 'domains' => ['domain1.*'], + 'prefixes' => ['prefix1/*'], + 'versions' => ['v1'], + ], + 'include' => [$includePattern], + ], + ]; + $matcher = new RouteMatcher(); + $routes = $matcher->getRoutes($routeRules, 'dingo'); + $oddRuleOut = collect($routes)->filter(function ($route) use ($mustInclude) { + return in_array($route['route']->getName(), $mustInclude); + }); + $this->assertCount(count($mustInclude), $oddRuleOut); + } + + public function testWillExcludeRouteIfListedExplicitlyForDingoRouter() + { + $this->registerDingoRoutes(); + + $mustNotInclude = 'v2.domain2'; + $routeRules = [ + [ + 'match' => [ + 'domains' => ['domain2.*'], + 'prefixes' => ['*'], + 'versions' => ['v2'], + ], + 'exclude' => [$mustNotInclude], + ], + ]; + $matcher = new RouteMatcher(); + $routes = $matcher->getRoutes($routeRules, 'dingo'); + $oddRuleOut = collect($routes)->filter(function ($route) use ($mustNotInclude) { + return $route['route']->getName() === $mustNotInclude; + }); + $this->assertCount(0, $oddRuleOut); + } + + public function testWillExcludeRouteIfMatchForAnExcludePatterForDingoRouter() + { + $this->registerDingoRoutes(); + + $mustNotInclude = ['v2.prefix1.domain2', 'v2.prefix2.domain2']; + $excludePattern = 'v2.*.domain2'; + $routeRules = [ + [ + 'match' => [ + 'domains' => ['domain2.*'], + 'prefixes' => ['*'], + 'versions' => ['v2'], + ], + 'exclude' => [$excludePattern], + ], + ]; + $matcher = new RouteMatcher(); + $routes = $matcher->getRoutes($routeRules, 'dingo'); + $oddRuleOut = collect($routes)->filter(function ($route) use ($mustNotInclude) { + return in_array($route['route']->getName(), $mustNotInclude); + }); + $this->assertCount(0, $oddRuleOut); + } + + public function testMergesRoutesFromDifferentRuleGroupsForDingoRouter() + { + $this->registerDingoRoutes(); + $routeRules = [ + [ + 'match' => [ + 'domains' => ['*'], + 'prefixes' => ['*'], + 'versions' => ['v1'], + ], + ], + [ + 'match' => [ + 'domains' => ['*'], + 'prefixes' => ['*'], + 'versions' => ['v2'], + ], + ], + ]; + + $matcher = new RouteMatcher(); + $routes = $matcher->getRoutes($routeRules, 'dingo'); + $this->assertCount(18, $routes); + + $routes = collect($routes); + $firstRuleGroup = $routes->filter(function ($route) { + return ! empty(array_intersect($route['route']->versions(), ['v1'])); + }); + $this->assertCount(12, $firstRuleGroup); + + $secondRuleGroup = $routes->filter(function ($route) { + return ! empty(array_intersect($route['route']->versions(), ['v2'])); + }); + $this->assertCount(6, $secondRuleGroup); + } + + private function registerDingoRoutes() + { + $api = app('api.router'); + $api->version('v1', function (Router $api) { + $api->group(['domain' => 'domain1.app.test'], function (Router $api) { + $api->post('/domain1-1', function () { + return 'hi'; + })->name('v1.domain1-1'); + $api->get('domain1-2', function () { + return 'hi'; + })->name('v1.domain1-2'); + $api->get('/prefix1/domain1-1', function () { + return 'hi'; + })->name('v1.prefix1.domain1-1'); + $api->get('prefix1/domain1-2', function () { + return 'hi'; + })->name('v1.prefix1.domain1-2'); + $api->get('/prefix2/domain1-1', function () { + return 'hi'; + })->name('v1.prefix2.domain1-1'); + $api->get('prefix2/domain1-2', function () { + return 'hi'; + })->name('v1.prefix2.domain1-2'); + }); + $api->group(['domain' => 'domain2.app.test'], function (Router $api) { + $api->post('/domain2-1', function () { + return 'hi'; + })->name('v1.domain2-1'); + $api->get('domain2-2', function () { + return 'hi'; + })->name('v1.domain2-2'); + $api->get('/prefix1/domain2-1', function () { + return 'hi'; + })->name('v1.prefix1.domain2-1'); + $api->get('prefix1/domain2-2', function () { + return 'hi'; + })->name('v1.prefix1.domain2-2'); + $api->get('/prefix2/domain2-1', function () { + return 'hi'; + })->name('v1.prefix2.domain2-1'); + $api->get('prefix2/domain2-2', function () { + return 'hi'; + })->name('v1.prefix2.domain2-2'); + }); + }); + $api->version('v2', function (Router $api) { + $api->group(['domain' => 'domain1.app.test'], function (Router $api) { + $api->post('/domain1', function () { + return 'hi'; + })->name('v2.domain1'); + $api->get('/prefix1/domain1', function () { + return 'hi'; + })->name('v2.prefix1.domain1'); + $api->get('/prefix2/domain1', function () { + return 'hi'; + })->name('v2.prefix2.domain1'); + }); + $api->group(['domain' => 'domain2.app.test'], function (Router $api) { + $api->post('/domain2', function () { + return 'hi'; + })->name('v2.domain2'); + $api->get('/prefix1/domain2', function () { + return 'hi'; + })->name('v2.prefix1.domain2'); + $api->get('/prefix2/domain2', function () { + return 'hi'; + })->name('v2.prefix2.domain2'); + }); + }); + } +} diff --git a/tests/Unit/RouteMatcherTest.php b/tests/Unit/RouteMatcherTest.php index 76e429d..860ba37 100644 --- a/tests/Unit/RouteMatcherTest.php +++ b/tests/Unit/RouteMatcherTest.php @@ -2,7 +2,6 @@ namespace Mpociot\ApiDoc\Tests\Unit; -use Dingo\Api\Routing\Router; use Illuminate\Support\Facades\Route as RouteFacade; use Illuminate\Support\Str; use Mpociot\ApiDoc\Matching\RouteMatcher; @@ -10,13 +9,6 @@ use Orchestra\Testbench\TestCase; class RouteMatcherTest extends TestCase { - protected function getPackageProviders($app) - { - return [ - \Dingo\Api\Provider\LaravelServiceProvider::class, - ]; - } - public function testRespectsDomainsRuleForLaravelRouter() { $this->registerLaravelRoutes(); @@ -49,39 +41,6 @@ class RouteMatcherTest extends TestCase } } - public function testRespectsDomainsRuleForDingoRouter() - { - $this->registerDingoRoutes(); - $routeRules[0]['match']['versions'] = ['v1']; - $routeRules[0]['match']['prefixes'] = ['*']; - - $routeRules[0]['match']['domains'] = ['*']; - $matcher = new RouteMatcher(); - $routes = $matcher->getRoutes($routeRules, 'dingo'); - $this->assertCount(12, $routes); - - $routeRules[0]['match']['domains'] = ['domain1.*', 'domain2.*']; - $matcher = new RouteMatcher(); - $routes = $matcher->getRoutes($routeRules, 'dingo'); - $this->assertCount(12, $routes); - - $routeRules[0]['match']['domains'] = ['domain1.*']; - $matcher = new RouteMatcher(); - $routes = $matcher->getRoutes($routeRules, 'dingo'); - $this->assertCount(6, $routes); - foreach ($routes as $route) { - $this->assertStringContainsString('domain1', $route['route']->getDomain()); - } - - $routeRules[0]['match']['domains'] = ['domain2.*']; - $matcher = new RouteMatcher(); - $routes = $matcher->getRoutes($routeRules, 'dingo'); - $this->assertCount(6, $routes); - foreach ($routes as $route) { - $this->assertStringContainsString('domain2', $route['route']->getDomain()); - } - } - public function testRespectsPrefixesRuleForLaravelRouter() { $this->registerLaravelRoutes(); @@ -114,61 +73,6 @@ class RouteMatcherTest extends TestCase } } - public function testRespectsPrefixesRuleForDingoRouter() - { - $this->registerDingoRoutes(); - $routeRules[0]['match']['versions'] = ['v1']; - $routeRules[0]['match']['domains'] = ['*']; - - $routeRules[0]['match']['prefixes'] = ['*']; - $matcher = new RouteMatcher(); - $routes = $matcher->getRoutes($routeRules, 'dingo'); - $this->assertCount(12, $routes); - - $routeRules[0]['match']['prefixes'] = ['prefix1/*', 'prefix2/*']; - $matcher = new RouteMatcher(); - $routes = $matcher->getRoutes($routeRules, 'dingo'); - $this->assertCount(8, $routes); - - $routeRules[0]['match']['prefixes'] = ['prefix1/*']; - $matcher = new RouteMatcher(); - $routes = $matcher->getRoutes($routeRules, 'dingo'); - $this->assertCount(4, $routes); - foreach ($routes as $route) { - $this->assertTrue(Str::is('prefix1/*', $route['route']->uri())); - } - - $routeRules[0]['match']['prefixes'] = ['prefix2/*']; - $matcher = new RouteMatcher(); - $routes = $matcher->getRoutes($routeRules, 'dingo'); - $this->assertCount(4, $routes); - foreach ($routes as $route) { - $this->assertTrue(Str::is('prefix2/*', $route['route']->uri())); - } - } - - public function testRespectsVersionsRuleForDingoRouter() - { - $this->registerDingoRoutes(); - - $routeRules[0]['match']['versions'] = ['v2']; - $routeRules[0]['match']['domains'] = ['*']; - $routeRules[0]['match']['prefixes'] = ['*']; - $matcher = new RouteMatcher(); - $routes = $matcher->getRoutes($routeRules, 'dingo'); - $this->assertCount(6, $routes); - foreach ($routes as $route) { - $this->assertNotEmpty(array_intersect($route['route']->versions(), ['v2'])); - } - - $routeRules[0]['match']['versions'] = ['v1', 'v2']; - $routeRules[0]['match']['domains'] = ['*']; - $routeRules[0]['match']['prefixes'] = ['*']; - $matcher = new RouteMatcher(); - $routes = $matcher->getRoutes($routeRules, 'dingo'); - $this->assertCount(18, $routes); - } - public function testWillIncludeRouteIfListedExplicitlyForLaravelRouter() { $this->registerLaravelRoutes(); @@ -185,29 +89,6 @@ class RouteMatcherTest extends TestCase $this->assertCount(1, $oddRuleOut); } - public function testWillIncludeRouteIfListedExplicitlyForDingoRouter() - { - $this->registerDingoRoutes(); - - $mustInclude = 'v2.domain2'; - $routeRules = [ - [ - 'match' => [ - 'domains' => ['domain1.*'], - 'prefixes' => ['prefix1/*'], - 'versions' => ['v1'], - ], - 'include' => [$mustInclude], - ], - ]; - $matcher = new RouteMatcher(); - $routes = $matcher->getRoutes($routeRules, 'dingo'); - $oddRuleOut = collect($routes)->filter(function ($route) use ($mustInclude) { - return $route['route']->getName() === $mustInclude; - }); - $this->assertCount(1, $oddRuleOut); - } - public function testWillIncludeRouteIfMatchForAnIncludePatternForLaravelRouter() { $this->registerLaravelRoutes(); @@ -225,30 +106,6 @@ class RouteMatcherTest extends TestCase $this->assertCount(count($mustInclude), $oddRuleOut); } - public function testWillIncludeRouteIfMatchForAnIncludePatternForDingoRouter() - { - $this->registerDingoRoutes(); - - $mustInclude = ['v2.domain1', 'v2.domain2']; - $includePattern = 'v2.domain*'; - $routeRules = [ - [ - 'match' => [ - 'domains' => ['domain1.*'], - 'prefixes' => ['prefix1/*'], - 'versions' => ['v1'], - ], - 'include' => [$includePattern], - ], - ]; - $matcher = new RouteMatcher(); - $routes = $matcher->getRoutes($routeRules, 'dingo'); - $oddRuleOut = collect($routes)->filter(function ($route) use ($mustInclude) { - return in_array($route['route']->getName(), $mustInclude); - }); - $this->assertCount(count($mustInclude), $oddRuleOut); - } - public function testWillExcludeRouteIfListedExplicitlyForLaravelRouter() { $this->registerLaravelRoutes(); @@ -265,29 +122,6 @@ class RouteMatcherTest extends TestCase $this->assertCount(0, $oddRuleOut); } - public function testWillExcludeRouteIfListedExplicitlyForDingoRouter() - { - $this->registerDingoRoutes(); - - $mustNotInclude = 'v2.domain2'; - $routeRules = [ - [ - 'match' => [ - 'domains' => ['domain2.*'], - 'prefixes' => ['*'], - 'versions' => ['v2'], - ], - 'exclude' => [$mustNotInclude], - ], - ]; - $matcher = new RouteMatcher(); - $routes = $matcher->getRoutes($routeRules, 'dingo'); - $oddRuleOut = collect($routes)->filter(function ($route) use ($mustNotInclude) { - return $route['route']->getName() === $mustNotInclude; - }); - $this->assertCount(0, $oddRuleOut); - } - public function testWillExcludeRouteIfMatchForAnExcludePatternForLaravelRouter() { $this->registerLaravelRoutes(); @@ -305,30 +139,6 @@ class RouteMatcherTest extends TestCase $this->assertCount(0, $oddRuleOut); } - public function testWillExcludeRouteIfMatchForAnExcludePatterForDingoRouter() - { - $this->registerDingoRoutes(); - - $mustNotInclude = ['v2.prefix1.domain2', 'v2.prefix2.domain2']; - $excludePattern = 'v2.*.domain2'; - $routeRules = [ - [ - 'match' => [ - 'domains' => ['domain2.*'], - 'prefixes' => ['*'], - 'versions' => ['v2'], - ], - 'exclude' => [$excludePattern], - ], - ]; - $matcher = new RouteMatcher(); - $routes = $matcher->getRoutes($routeRules, 'dingo'); - $oddRuleOut = collect($routes)->filter(function ($route) use ($mustNotInclude) { - return in_array($route['route']->getName(), $mustNotInclude); - }); - $this->assertCount(0, $oddRuleOut); - } - public function testMergesRoutesFromDifferentRuleGroupsForLaravelRouter() { $this->registerLaravelRoutes(); @@ -366,42 +176,6 @@ class RouteMatcherTest extends TestCase $this->assertCount(2, $secondRuleGroup); } - public function testMergesRoutesFromDifferentRuleGroupsForDingoRouter() - { - $this->registerDingoRoutes(); - $routeRules = [ - [ - 'match' => [ - 'domains' => ['*'], - 'prefixes' => ['*'], - 'versions' => ['v1'], - ], - ], - [ - 'match' => [ - 'domains' => ['*'], - 'prefixes' => ['*'], - 'versions' => ['v2'], - ], - ], - ]; - - $matcher = new RouteMatcher(); - $routes = $matcher->getRoutes($routeRules, 'dingo'); - $this->assertCount(18, $routes); - - $routes = collect($routes); - $firstRuleGroup = $routes->filter(function ($route) { - return ! empty(array_intersect($route['route']->versions(), ['v1'])); - }); - $this->assertCount(12, $firstRuleGroup); - - $secondRuleGroup = $routes->filter(function ($route) { - return ! empty(array_intersect($route['route']->versions(), ['v2'])); - }); - $this->assertCount(6, $secondRuleGroup); - } - private function registerLaravelRoutes() { RouteFacade::group(['domain' => 'domain1.app.test'], function () { @@ -445,75 +219,4 @@ class RouteMatcherTest extends TestCase })->name('prefix2.domain2-2'); }); } - - private function registerDingoRoutes() - { - $api = app('api.router'); - $api->version('v1', function (Router $api) { - $api->group(['domain' => 'domain1.app.test'], function (Router $api) { - $api->post('/domain1-1', function () { - return 'hi'; - })->name('v1.domain1-1'); - $api->get('domain1-2', function () { - return 'hi'; - })->name('v1.domain1-2'); - $api->get('/prefix1/domain1-1', function () { - return 'hi'; - })->name('v1.prefix1.domain1-1'); - $api->get('prefix1/domain1-2', function () { - return 'hi'; - })->name('v1.prefix1.domain1-2'); - $api->get('/prefix2/domain1-1', function () { - return 'hi'; - })->name('v1.prefix2.domain1-1'); - $api->get('prefix2/domain1-2', function () { - return 'hi'; - })->name('v1.prefix2.domain1-2'); - }); - $api->group(['domain' => 'domain2.app.test'], function (Router $api) { - $api->post('/domain2-1', function () { - return 'hi'; - })->name('v1.domain2-1'); - $api->get('domain2-2', function () { - return 'hi'; - })->name('v1.domain2-2'); - $api->get('/prefix1/domain2-1', function () { - return 'hi'; - })->name('v1.prefix1.domain2-1'); - $api->get('prefix1/domain2-2', function () { - return 'hi'; - })->name('v1.prefix1.domain2-2'); - $api->get('/prefix2/domain2-1', function () { - return 'hi'; - })->name('v1.prefix2.domain2-1'); - $api->get('prefix2/domain2-2', function () { - return 'hi'; - })->name('v1.prefix2.domain2-2'); - }); - }); - $api->version('v2', function (Router $api) { - $api->group(['domain' => 'domain1.app.test'], function (Router $api) { - $api->post('/domain1', function () { - return 'hi'; - })->name('v2.domain1'); - $api->get('/prefix1/domain1', function () { - return 'hi'; - })->name('v2.prefix1.domain1'); - $api->get('/prefix2/domain1', function () { - return 'hi'; - })->name('v2.prefix2.domain1'); - }); - $api->group(['domain' => 'domain2.app.test'], function (Router $api) { - $api->post('/domain2', function () { - return 'hi'; - })->name('v2.domain2'); - $api->get('/prefix1/domain2', function () { - return 'hi'; - })->name('v2.prefix1.domain2'); - $api->get('/prefix2/domain2', function () { - return 'hi'; - })->name('v2.prefix2.domain2'); - }); - }); - } }