Skip to content

Commit af1a09d

Browse files
committed
fix(openapi): tests
1 parent ff79fb9 commit af1a09d

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

src/Symfony/Tests/Action/DocumentationActionTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,35 @@ public function testHtmlFormatWhenReDocEnabledAndSwaggerUiDisabled(): void
9090
$this->assertInstanceOf(OpenApi::class, $result);
9191
}
9292

93+
public function testHtmlFormatWhenSwaggerUiEnabledAndReDocDisabled(): void
94+
{
95+
$request = new Request();
96+
$request->attributes->set('_format', 'html');
97+
98+
$openApiFactory = $this->createMock(OpenApiFactoryInterface::class);
99+
$resourceNameCollectionFactory = $this->createMock(ResourceNameCollectionFactoryInterface::class);
100+
$provider = $this->createMock(ProviderInterface::class);
101+
$provider->expects($this->once())->method('provide')->willReturn(new OpenApi(new Info('title', '1.0.0'), [], new Paths()));
102+
$processor = $this->createMock(ProcessorInterface::class);
103+
$processor->expects($this->once())->method('process')->willReturnArgument(0);
104+
105+
$documentation = new DocumentationAction(
106+
$resourceNameCollectionFactory,
107+
openApiFactory: $openApiFactory,
108+
provider: $provider,
109+
processor: $processor,
110+
documentationFormats: [
111+
'json' => ['application/json'],
112+
'html' => ['text/html'],
113+
],
114+
swaggerUiEnabled: true,
115+
reDocEnabled: false,
116+
);
117+
118+
$result = $documentation($request);
119+
$this->assertInstanceOf(OpenApi::class, $result);
120+
}
121+
93122
public function testJsonFormatWhenSwaggerUiDisabledIsAccessible(): void
94123
{
95124
$request = new Request();

src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ public function testSwaggerUiDisabledConfiguration(): void
268268
$config = self::DEFAULT_CONFIG;
269269
$config['api_platform']['enable_swagger'] = true;
270270
$config['api_platform']['enable_swagger_ui'] = false;
271+
$config['api_platform']['enable_re_doc'] = false;
271272
$config['api_platform']['use_symfony_listeners'] = true;
272273

273274
(new ApiPlatformExtension())->load($config, $this->container);
@@ -300,6 +301,26 @@ public function testSwaggerUiEnabledConfiguration(): void
300301
$this->assertContainerHas($services);
301302
}
302303

304+
public function testReDocEnabledWithSwaggerUiDisabledConfiguration(): void
305+
{
306+
$config = self::DEFAULT_CONFIG;
307+
$config['api_platform']['enable_swagger'] = true;
308+
$config['api_platform']['enable_swagger_ui'] = false;
309+
$config['api_platform']['enable_re_doc'] = true;
310+
$config['api_platform']['use_symfony_listeners'] = true;
311+
312+
(new ApiPlatformExtension())->load($config, $this->container);
313+
314+
$services = [
315+
'api_platform.swagger_ui.processor',
316+
'api_platform.swagger_ui.context',
317+
'api_platform.swagger_ui.provider',
318+
'api_platform.swagger_ui.documentation.provider',
319+
];
320+
321+
$this->assertContainerHas($services);
322+
}
323+
303324
public function testEventListenersConfiguration(): void
304325
{
305326
$config = self::DEFAULT_CONFIG;

tests/Functional/DocumentationActionTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,22 @@ public function testHtmlDocumentationIsAccessibleWhenReDocEnabledAndSwaggerUiDis
110110
$this->assertStringNotContainsString('Swagger UI and ReDoc are disabled.', $client->getResponse()->getContent(false));
111111
}
112112

113+
public function testHtmlDocumentationIsAccessibleWhenSwaggerUiEnabledAndReDocDisabled(): void
114+
{
115+
DocumentationActionAppKernel::$swaggerUiEnabled = true;
116+
DocumentationActionAppKernel::$reDocEnabled = false;
117+
118+
$client = self::createClient();
119+
120+
$container = static::getContainer();
121+
$this->assertTrue($container->getParameter('api_platform.enable_swagger_ui'));
122+
$this->assertFalse($container->getParameter('api_platform.enable_re_doc'));
123+
124+
$client->request('GET', '/docs', ['headers' => ['Accept' => 'text/html']]);
125+
$this->assertResponseIsSuccessful();
126+
$this->assertStringNotContainsString('Swagger UI and ReDoc are disabled.', $client->getResponse()->getContent(false));
127+
}
128+
113129
public function testHtmlDocumentationIsAccessibleWhenSwaggerUiIsEnabled(): void
114130
{
115131
DocumentationActionAppKernel::$swaggerUiEnabled = true;

0 commit comments

Comments
 (0)