2018-01-05 13:08:02 +01: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 .
*/
namespace Nelmio\ApiDocBundle\Tests\DependencyInjection ;
use Nelmio\ApiDocBundle\DependencyInjection\Configuration ;
use PHPUnit\Framework\TestCase ;
use Symfony\Component\Config\Definition\Processor ;
class ConfigurationTest extends TestCase
{
public function testDefaultArea ()
{
$processor = new Processor ();
$config = $processor -> processConfiguration ( new Configuration (), [[ 'areas' => [ 'path_patterns' => [ '/foo' ]]]]);
2019-01-05 16:37:43 +01:00
$this -> assertSame (
[
'default' => [
'path_patterns' => [ '/foo' ],
'host_patterns' => [],
2019-04-16 18:22:51 +03:00
'name_patterns' => [],
2019-01-05 16:37:43 +01:00
'with_annotation' => false ,
'documentation' => [],
],
],
$config [ 'areas' ]
);
2018-01-05 13:08:02 +01:00
}
public function testAreas ()
{
$processor = new Processor ();
$config = $processor -> processConfiguration ( new Configuration (), [[ 'areas' => $areas = [
2019-01-05 16:37:43 +01:00
'default' => [
'path_patterns' => [ '/foo' ],
'host_patterns' => [],
'with_annotation' => false ,
'documentation' => [],
2019-04-16 18:22:51 +03:00
'name_patterns' => [],
2019-01-05 16:37:43 +01:00
],
'internal' => [
'path_patterns' => [ '/internal' ],
'host_patterns' => [ '^swagger\.' ],
'with_annotation' => false ,
'documentation' => [],
2019-04-16 18:22:51 +03:00
'name_patterns' => [],
2019-01-05 16:37:43 +01:00
],
'commercial' => [
'path_patterns' => [ '/internal' ],
'host_patterns' => [],
'with_annotation' => false ,
'documentation' => [],
2019-04-16 18:22:51 +03:00
'name_patterns' => [],
2019-01-05 16:37:43 +01:00
],
2018-01-05 13:08:02 +01:00
]]]);
2018-03-13 12:40:36 -03:00
$this -> assertSame ( $areas , $config [ 'areas' ]);
2018-01-05 13:08:02 +01:00
}
2018-06-10 09:56:38 +02:00
public function testAlternativeNames ()
{
$processor = new Processor ();
$config = $processor -> processConfiguration ( new Configuration (), [[
'models' => [
'names' => [
[
'alias' => 'Foo1' ,
'type' => 'App\Foo' ,
'groups' => [ 'group' ],
],
[
'alias' => 'Foo2' ,
'type' => 'App\Foo' ,
'groups' => [],
],
[
'alias' => 'Foo3' ,
'type' => 'App\Foo' ,
],
[
'alias' => 'Foo4' ,
'type' => 'App\Foo' ,
'groups' => [ 'group' ],
'areas' => [ 'internal' ],
],
[
'alias' => 'Foo1' ,
'type' => 'App\Foo' ,
'areas' => [ 'internal' ],
],
2018-07-25 17:58:28 +02:00
[
'alias' => 'Foo1' ,
'type' => 'App\Foo' ,
'groups' => [ 'group1' , [ 'group2' , 'parent' => 'child3' ]],
],
2018-06-10 09:56:38 +02:00
],
],
]]);
$this -> assertEquals ([
[
'alias' => 'Foo1' ,
'type' => 'App\Foo' ,
'groups' => [ 'group' ],
'areas' => [],
],
[
'alias' => 'Foo2' ,
'type' => 'App\Foo' ,
'groups' => [],
'areas' => [],
],
[
'alias' => 'Foo3' ,
'type' => 'App\Foo' ,
2018-08-26 22:15:44 +02:00
'groups' => null ,
2018-06-10 09:56:38 +02:00
'areas' => [],
],
[
'alias' => 'Foo4' ,
'type' => 'App\\Foo' ,
'groups' => [ 'group' ],
'areas' => [ 'internal' ],
],
[
'alias' => 'Foo1' ,
'type' => 'App\\Foo' ,
2018-08-26 22:15:44 +02:00
'groups' => null ,
2018-06-10 09:56:38 +02:00
'areas' => [ 'internal' ],
],
2018-07-25 17:58:28 +02:00
[
'alias' => 'Foo1' ,
'type' => 'App\Foo' ,
'groups' => [ 'group1' , [ 'group2' , 'parent' => 'child3' ]],
'areas' => [],
],
2018-06-10 09:56:38 +02:00
], $config [ 'models' ][ 'names' ]);
}
2018-01-05 13:08:02 +01:00
/**
* @ group legacy
*/
public function testBothAreasAndRoutes ()
{
2020-12-10 21:59:36 +01:00
$this -> expectException ( \InvalidArgumentException :: class );
$this -> expectExceptionMessage ( 'You must not use both `nelmio_api_doc.areas` and `nelmio_api_doc.routes` config options. Please update your config to only use `nelmio_api_doc.areas`.' );
2018-01-05 13:08:02 +01:00
$processor = new Processor ();
$config = $processor -> processConfiguration ( new Configuration (), [[ 'areas' => [], 'routes' => []]]);
}
/**
* @ group legacy
* @ expectedDeprecation The `nelmio_api_doc.routes` config option is deprecated . Please use `nelmio_api_doc.areas` instead ( just replace `routes` by `areas` in your config ) .
*/
public function testDefaultConfig ()
{
$processor = new Processor ();
$config = $processor -> processConfiguration ( new Configuration (), [[ 'routes' => [ 'path_patterns' => [ '/foo' ]]]]);
2019-01-05 16:37:43 +01:00
$this -> assertSame (
[
'default' => [
'path_patterns' => [ '/foo' ],
'host_patterns' => [],
2019-04-16 18:22:51 +03:00
'name_patterns' => [],
2019-01-05 16:37:43 +01:00
'with_annotation' => false ,
'documentation' => [],
],
],
$config [ 'areas' ]
);
2018-01-05 13:08:02 +01:00
}
}