setParameter('kernel.bundles', []); $extension = new NelmioApiDocExtension(); $extension->load([[ 'areas' => [ '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() { $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)); } }