2017-08-08 19:32:53 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the NelmioApiDocBundle package.
|
|
|
|
*
|
|
|
|
* (c) Nelmio
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2018-01-04 14:33:02 +01:00
|
|
|
namespace Nelmio\ApiDocBundle\Tests\DependencyInjection;
|
2017-08-08 19:32:53 +02:00
|
|
|
|
|
|
|
use Nelmio\ApiDocBundle\DependencyInjection\NelmioApiDocExtension;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
|
|
|
|
class NelmioApiDocExtensionTest extends TestCase
|
|
|
|
{
|
2018-06-10 09:56:38 +02:00
|
|
|
public function testNameAliasesArePassedToModelRegistry()
|
|
|
|
{
|
|
|
|
$container = new ContainerBuilder();
|
|
|
|
$container->setParameter('kernel.bundles', []);
|
|
|
|
$extension = new NelmioApiDocExtension();
|
|
|
|
$extension->load([[
|
|
|
|
'areas' => [
|
2018-07-27 09:44:19 +05:00
|
|
|
'default' => ['path_patterns' => ['/foo'], 'host_patterns' => [], 'documentation' => []],
|
|
|
|
'commercial' => ['path_patterns' => ['/internal'], 'host_patterns' => [], 'documentation' => []],
|
2018-06-10 09:56:38 +02:00
|
|
|
],
|
|
|
|
'models' => [
|
|
|
|
'names' => [
|
|
|
|
[ // Test1 alias for all the areas
|
|
|
|
'alias' => 'Test1',
|
|
|
|
'type' => 'App\Test',
|
|
|
|
],
|
|
|
|
[ // Foo1 alias for all the areas
|
|
|
|
'alias' => 'Foo1',
|
|
|
|
'type' => 'App\Foo',
|
|
|
|
],
|
|
|
|
[ // overwrite Foo1 alias for all the commercial area
|
|
|
|
'alias' => 'Foo1',
|
|
|
|
'type' => 'App\Bar',
|
|
|
|
'areas' => ['commercial'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]], $container);
|
|
|
|
|
|
|
|
$methodCalls = $container->getDefinition('nelmio_api_doc.generator.default')->getMethodCalls();
|
|
|
|
$foundMethodCall = false;
|
|
|
|
foreach ($methodCalls as $methodCall) {
|
|
|
|
if ('setAlternativeNames' === $methodCall[0]) {
|
|
|
|
$this->assertEquals([
|
|
|
|
'Foo1' => [
|
|
|
|
'type' => 'App\\Foo',
|
|
|
|
'groups' => [],
|
|
|
|
],
|
|
|
|
'Test1' => [
|
|
|
|
'type' => 'App\\Test',
|
|
|
|
'groups' => [],
|
|
|
|
],
|
|
|
|
], $methodCall[1][0]);
|
|
|
|
$foundMethodCall = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->assertTrue($foundMethodCall);
|
|
|
|
|
|
|
|
$methodCalls = $container->getDefinition('nelmio_api_doc.generator.commercial')->getMethodCalls();
|
|
|
|
$foundMethodCall = false;
|
|
|
|
foreach ($methodCalls as $methodCall) {
|
|
|
|
if ('setAlternativeNames' === $methodCall[0]) {
|
|
|
|
$this->assertEquals([
|
|
|
|
'Foo1' => [
|
|
|
|
'type' => 'App\\Bar',
|
|
|
|
'groups' => [],
|
|
|
|
],
|
|
|
|
'Test1' => [
|
|
|
|
'type' => 'App\\Test',
|
|
|
|
'groups' => [],
|
|
|
|
],
|
|
|
|
], $methodCall[1][0]);
|
|
|
|
$foundMethodCall = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->assertTrue($foundMethodCall);
|
|
|
|
}
|
|
|
|
|
2017-08-08 19:32:53 +02:00
|
|
|
public function testMergesRootKeysFromMultipleConfigurations()
|
|
|
|
{
|
|
|
|
$container = new ContainerBuilder();
|
|
|
|
$container->setParameter('kernel.bundles', []);
|
|
|
|
$extension = new NelmioApiDocExtension();
|
|
|
|
$extension->load([
|
|
|
|
[
|
2018-07-27 09:44:19 +05:00
|
|
|
'areas' => [
|
|
|
|
'default' => [
|
|
|
|
'documentation' => [
|
|
|
|
'info' => [
|
|
|
|
'title' => 'API documentation',
|
|
|
|
'description' => 'This is the api documentation, use it wisely',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]
|
|
|
|
]
|
2017-08-08 19:32:53 +02:00
|
|
|
],
|
|
|
|
[
|
2018-07-27 09:44:19 +05:00
|
|
|
'areas' => [
|
|
|
|
'default' => [
|
|
|
|
'documentation' => [
|
|
|
|
'tags' => [
|
|
|
|
[
|
|
|
|
'name' => 'secured',
|
|
|
|
'description' => 'Requires authentication',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => 'another',
|
|
|
|
'description' => 'Another tag serving another purpose',
|
|
|
|
],
|
|
|
|
],
|
2017-08-08 19:32:53 +02:00
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
2018-07-27 09:44:19 +05:00
|
|
|
'areas' => [
|
|
|
|
'default' => [
|
|
|
|
'documentation' => [
|
|
|
|
'paths' => [
|
|
|
|
'/api/v1/model' => [
|
|
|
|
'get' => [
|
|
|
|
'tags' => ['secured'],
|
|
|
|
],
|
|
|
|
],
|
2017-08-08 19:32:53 +02:00
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
], $container);
|
|
|
|
|
|
|
|
$this->assertSame([
|
|
|
|
'info' => [
|
|
|
|
'title' => 'API documentation',
|
|
|
|
'description' => 'This is the api documentation, use it wisely',
|
|
|
|
],
|
|
|
|
'tags' => [
|
|
|
|
[
|
|
|
|
'name' => 'secured',
|
|
|
|
'description' => 'Requires authentication',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => 'another',
|
|
|
|
'description' => 'Another tag serving another purpose',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'paths' => [
|
|
|
|
'/api/v1/model' => [
|
|
|
|
'get' => [
|
|
|
|
'tags' => ['secured'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2018-07-27 09:44:19 +05:00
|
|
|
], $container->getDefinition('nelmio_api_doc.describers.config.default')->getArgument(0));
|
2017-08-08 19:32:53 +02:00
|
|
|
}
|
|
|
|
}
|