Skip to content

Commit 9bfae20

Browse files
committed
Add tests for route filtering
1 parent 512cfee commit 9bfae20

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

tests/GeneratorTest.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public function testHasPaths($docs)
4343
$this->assertEquals([
4444
'/users',
4545
'/users/{id}',
46+
'/api',
47+
'/api/store',
4648
], array_keys($docs['paths']));
4749

4850
return $docs['paths'];
@@ -105,4 +107,34 @@ public function testOptionalData()
105107
$this->assertContains('application/json', $docs['consumes']);
106108
$this->assertContains('application/json', $docs['produces']);
107109
}
108-
}
110+
111+
/**
112+
* @param string|null $routeFilter
113+
* @param array $expectedRoutes
114+
*
115+
* @dataProvider filtersRoutesProvider
116+
*/
117+
public function testFiltersRoutes($routeFilter, $expectedRoutes)
118+
{
119+
$this->generator = new Generator(
120+
$this->config = config('laravel-swagger'),
121+
$routeFilter
122+
);
123+
124+
$docs = $this->generator->generate();
125+
126+
$this->assertEquals($expectedRoutes, array_keys($docs['paths']));
127+
}
128+
129+
/**
130+
* @return array
131+
*/
132+
public function filtersRoutesProvider()
133+
{
134+
return [
135+
'No Filter' => [null, ['/users', '/users/{id}', '/api', '/api/store']],
136+
'/api Filter' => ['/api', ['/api', '/api/store']],
137+
'/=nonexistant Filter' => ['/nonexistant', []],
138+
];
139+
}
140+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Mtrajano\LaravelSwagger\Tests\Stubs\Controllers;
4+
5+
use Illuminate\Routing\Controller;
6+
7+
class ApiController extends Controller
8+
{
9+
public function index()
10+
{
11+
return json_encode(['result' => 'success']);
12+
}
13+
14+
public function store()
15+
{
16+
return json_encode(['result' => 'success']);
17+
}
18+
}

tests/TestCase.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ protected function getEnvironmentSetUp($app)
1616
$app['router']->get('/users', 'Mtrajano\\LaravelSwagger\\Tests\\Stubs\\Controllers\\UserController@index');
1717
$app['router']->get('/users/{id}', 'Mtrajano\\LaravelSwagger\\Tests\\Stubs\\Controllers\\UserController@show');
1818
$app['router']->post('/users', 'Mtrajano\\LaravelSwagger\\Tests\\Stubs\\Controllers\\UserController@store');
19+
$app['router']->get('/api', 'Mtrajano\\LaravelSwagger\\Tests\\Stubs\\Controllers\\ApiController@index');
20+
$app['router']->put('/api/store', 'Mtrajano\\LaravelSwagger\\Tests\\Stubs\\Controllers\\ApiController@store');
1921
}
20-
}
22+
}

0 commit comments

Comments
 (0)