mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-03 08:09:25 +03:00
ab005c4129
* implement alternative naming system via configuration * use strict comparison * test di configs * rever * test naming aliases are applied * set "default" as default area * test names are passed to generators * cs formatting * added extra check for built-int types * cs * added documentation about alternative names * allow to create the same alias in two different areas * document and test better aliasing strategy * specify that the last matching rule is used * Make last matching rule wins * Fix documentation
154 lines
5.2 KiB
PHP
154 lines
5.2 KiB
PHP
<?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.
|
|
*/
|
|
|
|
namespace Nelmio\ApiDocBundle\Tests\DependencyInjection;
|
|
|
|
use Nelmio\ApiDocBundle\DependencyInjection\NelmioApiDocExtension;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
class NelmioApiDocExtensionTest extends TestCase
|
|
{
|
|
public function testNameAliasesArePassedToModelRegistry()
|
|
{
|
|
$container = new ContainerBuilder();
|
|
$container->setParameter('kernel.bundles', []);
|
|
$extension = new NelmioApiDocExtension();
|
|
$extension->load([[
|
|
'areas' => [
|
|
'default' => ['path_patterns' => ['/foo'], 'host_patterns' => []],
|
|
'commercial' => ['path_patterns' => ['/internal'], 'host_patterns' => []],
|
|
],
|
|
'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);
|
|
}
|
|
|
|
public function testMergesRootKeysFromMultipleConfigurations()
|
|
{
|
|
$container = new ContainerBuilder();
|
|
$container->setParameter('kernel.bundles', []);
|
|
$extension = new NelmioApiDocExtension();
|
|
$extension->load([
|
|
[
|
|
'documentation' => [
|
|
'info' => [
|
|
'title' => 'API documentation',
|
|
'description' => 'This is the api documentation, use it wisely',
|
|
],
|
|
],
|
|
],
|
|
[
|
|
'documentation' => [
|
|
'tags' => [
|
|
[
|
|
'name' => 'secured',
|
|
'description' => 'Requires authentication',
|
|
],
|
|
[
|
|
'name' => 'another',
|
|
'description' => 'Another tag serving another purpose',
|
|
],
|
|
],
|
|
],
|
|
],
|
|
[
|
|
'documentation' => [
|
|
'paths' => [
|
|
'/api/v1/model' => [
|
|
'get' => [
|
|
'tags' => ['secured'],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
], $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'],
|
|
],
|
|
],
|
|
],
|
|
], $container->getDefinition('nelmio_api_doc.describers.config')->getArgument(0));
|
|
}
|
|
}
|