NelmioApiDocBundle/Tests/DependencyInjection/NelmioApiDocExtensionTest.php

163 lines
5.5 KiB
PHP
Raw Normal View History

<?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;
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' => [
2018-07-27 09:44:19 +05:00
'default' => ['path_patterns' => ['/foo'], 'host_patterns' => [], 'documentation' => []],
'commercial' => ['path_patterns' => ['/internal'], 'host_patterns' => [], 'documentation' => []],
],
'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()
{
2018-09-25 16:42:56 +05:00
/**
* areas:
default:
path_patterns: '%client_api_regexp_filter%'
host_patterns: ['%domain.client%']
*/
$container = new ContainerBuilder();
$container->setParameter('kernel.bundles', []);
$extension = new NelmioApiDocExtension();
$extension->load([
[
2018-09-25 16:42:56 +05:00
'areas' => [
'default' => []
],
2018-08-14 12:30:38 +05:00
'documentation' => [
'info' => [
'title' => 'API documentation',
'description' => 'This is the api documentation, use it wisely',
],
],
],
[
2018-08-14 12:30:38 +05:00
'documentation' => [
'tags' => [
[
'name' => 'secured',
'description' => 'Requires authentication',
],
[
'name' => 'another',
'description' => 'Another tag serving another purpose',
],
],
],
],
[
2018-08-14 12:30:38 +05:00
'documentation' => [
'paths' => [
'/api/v1/model' => [
'get' => [
'tags' => ['secured'],
],
],
],
],
],
], $container);
2018-09-25 16:42:56 +05:00
$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-09-25 16:42:56 +05:00
], $container->getDefinition('nelmio_api_doc.describers.config.default')->getArgument(0));
}
}