Skip to content

Commit 23dc74b

Browse files
committed
test: add tests in DocumentationActionTest
1 parent bbfa764 commit 23dc74b

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/Symfony/Tests/Action/DocumentationActionTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Prophecy\Argument;
2828
use Prophecy\PhpUnit\ProphecyTrait;
2929
use Symfony\Component\HttpFoundation\Request;
30+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
3031

3132
/**
3233
* @author Amrouche Hamza <[email protected]>
@@ -35,6 +36,50 @@ class DocumentationActionTest extends TestCase
3536
{
3637
use ProphecyTrait;
3738

39+
public function testHtmlFormatWhenSwaggerUiDisabledThrows404(): void
40+
{
41+
$this->expectException(NotFoundHttpException::class);
42+
$this->expectExceptionMessage('Swagger UI is disabled.');
43+
44+
$request = new Request();
45+
$request->attributes->set('_format', 'html');
46+
47+
$openApiFactory = $this->createMock(OpenApiFactoryInterface::class);
48+
$resourceNameCollectionFactory = $this->createMock(ResourceNameCollectionFactoryInterface::class);
49+
50+
$documentation = new DocumentationAction(
51+
$resourceNameCollectionFactory,
52+
openApiFactory: $openApiFactory,
53+
documentationFormats: [
54+
'json' => ['application/json'],
55+
'html' => ['text/html'],
56+
],
57+
swaggerUiEnabled: false,
58+
);
59+
60+
$documentation($request);
61+
}
62+
63+
public function testJsonFormatWhenSwaggerUiDisabledIsAccessible(): void
64+
{
65+
$request = new Request();
66+
$request->attributes->set('_format', 'json');
67+
68+
$openApiFactory = $this->createMock(OpenApiFactoryInterface::class);
69+
$openApiFactory->expects($this->once())->method('__invoke')->willReturn(new OpenApi(new Info('title', '1.0.0'), [], new Paths()));
70+
71+
$resourceNameCollectionFactory = $this->createMock(ResourceNameCollectionFactoryInterface::class);
72+
73+
$documentation = new DocumentationAction(
74+
$resourceNameCollectionFactory,
75+
openApiFactory: $openApiFactory,
76+
swaggerUiEnabled: false
77+
);
78+
79+
$result = $documentation($request);
80+
$this->assertInstanceOf(OpenApi::class, $result);
81+
}
82+
3883
public function testDocumentationAction(): void
3984
{
4085
$openApi = new OpenApi(new Info('my api', '1.0.0'), [], new Paths());

0 commit comments

Comments
 (0)