Fix tests

This commit is contained in:
bifidokk 2018-07-27 09:44:19 +05:00
parent 5a6145fac8
commit f63ab23fe5
5 changed files with 86 additions and 38 deletions

View File

@ -42,10 +42,10 @@ final class Configuration implements ConfigurationInterface
->children() ->children()
->arrayNode('areas') ->arrayNode('areas')
->info('Filter the routes that are documented') ->info('Filter the routes that are documented')
->defaultValue(['default' => ['path_patterns' => [], 'host_patterns' => []]]) ->defaultValue(['default' => ['path_patterns' => [], 'host_patterns' => [], 'documentation' => []]])
->beforeNormalization() ->beforeNormalization()
->ifTrue(function ($v) { ->ifTrue(function ($v) {
return 0 === count($v) || isset($v['path_patterns']) || isset($v['host_patterns']); return 0 === count($v) || isset($v['path_patterns']) || isset($v['host_patterns']) || isset($v['documentation']);
}) })
->then(function ($v) { ->then(function ($v) {
return ['default' => $v]; return ['default' => $v];

View File

@ -20,18 +20,18 @@ class ConfigurationTest extends TestCase
public function testDefaultArea() public function testDefaultArea()
{ {
$processor = new Processor(); $processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), [['areas' => ['path_patterns' => ['/foo']]]]); $config = $processor->processConfiguration(new Configuration(), [['areas' => ['path_patterns' => ['/foo'], 'host_patterns' => [], 'documentation' => []]]]);
$this->assertSame(['default' => ['path_patterns' => ['/foo'], 'host_patterns' => []]], $config['areas']); $this->assertSame(['default' => ['path_patterns' => ['/foo'], 'host_patterns' => [], 'documentation' => []]], $config['areas']);
} }
public function testAreas() public function testAreas()
{ {
$processor = new Processor(); $processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), [['areas' => $areas = [ $config = $processor->processConfiguration(new Configuration(), [['areas' => $areas = [
'default' => ['path_patterns' => ['/foo'], 'host_patterns' => []], 'default' => ['path_patterns' => ['/foo'], 'host_patterns' => [], 'documentation' => []],
'internal' => ['path_patterns' => ['/internal'], 'host_patterns' => ['^swagger\.']], 'internal' => ['path_patterns' => ['/internal'], 'host_patterns' => ['^swagger\.'], 'documentation' => []],
'commercial' => ['path_patterns' => ['/internal'], 'host_patterns' => []], 'commercial' => ['path_patterns' => ['/internal'], 'host_patterns' => [], 'documentation' => []],
]]]); ]]]);
$this->assertSame($areas, $config['areas']); $this->assertSame($areas, $config['areas']);
@ -136,6 +136,6 @@ class ConfigurationTest extends TestCase
$processor = new Processor(); $processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), [['routes' => ['path_patterns' => ['/foo']]]]); $config = $processor->processConfiguration(new Configuration(), [['routes' => ['path_patterns' => ['/foo']]]]);
$this->assertSame(['default' => ['path_patterns' => ['/foo'], 'host_patterns' => []]], $config['areas']); $this->assertSame(['default' => ['path_patterns' => ['/foo'], 'host_patterns' => [], 'documentation' => []]], $config['areas']);
} }
} }

View File

@ -24,8 +24,8 @@ class NelmioApiDocExtensionTest extends TestCase
$extension = new NelmioApiDocExtension(); $extension = new NelmioApiDocExtension();
$extension->load([[ $extension->load([[
'areas' => [ 'areas' => [
'default' => ['path_patterns' => ['/foo'], 'host_patterns' => []], 'default' => ['path_patterns' => ['/foo'], 'host_patterns' => [], 'documentation' => []],
'commercial' => ['path_patterns' => ['/internal'], 'host_patterns' => []], 'commercial' => ['path_patterns' => ['/internal'], 'host_patterns' => [], 'documentation' => []],
], ],
'models' => [ 'models' => [
'names' => [ 'names' => [
@ -92,33 +92,45 @@ class NelmioApiDocExtensionTest extends TestCase
$extension = new NelmioApiDocExtension(); $extension = new NelmioApiDocExtension();
$extension->load([ $extension->load([
[ [
'documentation' => [ 'areas' => [
'info' => [ 'default' => [
'title' => 'API documentation', 'documentation' => [
'description' => 'This is the api documentation, use it wisely', 'info' => [
], 'title' => 'API documentation',
], 'description' => 'This is the api documentation, use it wisely',
],
],
]
]
], ],
[ [
'documentation' => [ 'areas' => [
'tags' => [ 'default' => [
[ 'documentation' => [
'name' => 'secured', 'tags' => [
'description' => 'Requires authentication', [
], 'name' => 'secured',
[ 'description' => 'Requires authentication',
'name' => 'another', ],
'description' => 'Another tag serving another purpose', [
'name' => 'another',
'description' => 'Another tag serving another purpose',
],
],
], ],
], ],
], ],
], ],
[ [
'documentation' => [ 'areas' => [
'paths' => [ 'default' => [
'/api/v1/model' => [ 'documentation' => [
'get' => [ 'paths' => [
'tags' => ['secured'], '/api/v1/model' => [
'get' => [
'tags' => ['secured'],
],
],
], ],
], ],
], ],
@ -148,6 +160,6 @@ class NelmioApiDocExtensionTest extends TestCase
], ],
], ],
], ],
], $container->getDefinition('nelmio_api_doc.describers.config')->getArgument(0)); ], $container->getDefinition('nelmio_api_doc.describers.config.default')->getArgument(0));
} }
} }

View File

@ -59,6 +59,7 @@ class SwaggerUiTest extends WebTestCase
$client = self::createClient(); $client = self::createClient();
$crawler = $client->request('GET', '/app_dev.php/docs.json'); $crawler = $client->request('GET', '/app_dev.php/docs.json');
$response = $client->getResponse(); $response = $client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('application/json', $response->headers->get('Content-Type')); $this->assertEquals('application/json', $response->headers->get('Content-Type'));

View File

@ -117,7 +117,47 @@ class TestKernel extends Kernel
// Filter routes // Filter routes
$c->loadFromExtension('nelmio_api_doc', [ $c->loadFromExtension('nelmio_api_doc', [
'documentation' => [ 'areas' => [
'default' => ['path_patterns' => ['^/api(?!/admin)'], 'host_patterns' => ['^api\.'], 'documentation' => [
'info' => [
'title' => 'My Test App',
],
'definitions' => [
'Test' => [
'type' => 'string',
],
],
'parameters' => [
'test' => [
'name' => 'id',
'in' => 'path',
'required' => true,
],
],
]],
'test' => ['path_patterns' => ['^/test'], 'host_patterns' => ['^api-test\.'], 'documentation' => [
'info' => [
'title' => 'My Test App',
],
'definitions' => [
'Test' => [
'type' => 'string',
],
],
'parameters' => [
'test' => [
'name' => 'id',
'in' => 'path',
'required' => true,
],
],
]],
],
]);
}
/*
* 'documentation' => [
'info' => [ 'info' => [
'title' => 'My Test App', 'title' => 'My Test App',
], ],
@ -134,12 +174,7 @@ class TestKernel extends Kernel
], ],
], ],
], ],
'areas' => [ */
'default' => ['path_patterns' => ['^/api(?!/admin)'], 'host_patterns' => ['^api\.']],
'test' => ['path_patterns' => ['^/test'], 'host_patterns' => ['^api-test\.']],
],
]);
}
/** /**
* {@inheritdoc} * {@inheritdoc}