|
14 | 14 | namespace ApiPlatform\Tests\Documentation\Action;
|
15 | 15 |
|
16 | 16 | use ApiPlatform\Documentation\Action\DocumentationAction;
|
| 17 | +use ApiPlatform\Documentation\Documentation; |
17 | 18 | use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
|
| 19 | +use ApiPlatform\Metadata\Resource\ResourceNameCollection; |
18 | 20 | use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface;
|
19 | 21 | use ApiPlatform\OpenApi\Model\Info;
|
20 | 22 | use ApiPlatform\OpenApi\Model\Paths;
|
@@ -46,11 +48,31 @@ public function testDocumentationAction(): void
|
46 | 48 | $requestProphecy->query = $queryProphecy->reveal();
|
47 | 49 | $requestProphecy->getBaseUrl()->willReturn('/api')->shouldBeCalledTimes(1);
|
48 | 50 | $queryProphecy->getBoolean('api_gateway')->willReturn(true)->shouldBeCalledTimes(1);
|
49 |
| - $attributesProphecy->all()->willReturn(['_api_normalization_context' => ['foo' => 'bar', 'base_url' => '/api', 'api_gateway' => true]])->shouldBeCalledTimes(1); |
50 | 51 | $attributesProphecy->get('_api_normalization_context', [])->willReturn(['foo' => 'bar'])->shouldBeCalledTimes(1);
|
51 | 52 | $attributesProphecy->set('_api_normalization_context', ['foo' => 'bar', 'base_url' => '/api', 'api_gateway' => true])->shouldBeCalledTimes(1);
|
52 | 53 |
|
53 | 54 | $documentation = new DocumentationAction($this->prophesize(ResourceNameCollectionFactoryInterface::class)->reveal(), 'my api', '', '1.0.0', $openApiFactoryProphecy->reveal());
|
54 | 55 | $this->assertInstanceOf(OpenApi::class, $documentation($requestProphecy->reveal()));
|
55 | 56 | }
|
| 57 | + |
| 58 | + public function testDocumentationActionWithoutOpenApiFactory(): void |
| 59 | + { |
| 60 | + $openApiFactoryProphecy = $this->prophesize(OpenApiFactoryInterface::class); |
| 61 | + $openApiFactoryProphecy->__invoke(Argument::any())->shouldNotBeCalled(); |
| 62 | + $requestProphecy = $this->prophesize(Request::class); |
| 63 | + $requestProphecy->getRequestFormat()->willReturn('json'); |
| 64 | + $attributesProphecy = $this->prophesize(ParameterBagInterface::class); |
| 65 | + $queryProphecy = $this->prophesize(ParameterBag::class); |
| 66 | + $requestProphecy->attributes = $attributesProphecy->reveal(); |
| 67 | + $requestProphecy->query = $queryProphecy->reveal(); |
| 68 | + $requestProphecy->getBaseUrl()->willReturn('/api')->shouldBeCalledTimes(1); |
| 69 | + $queryProphecy->getBoolean('api_gateway')->willReturn(true)->shouldBeCalledTimes(1); |
| 70 | + $attributesProphecy->get('_api_normalization_context', [])->willReturn(['foo' => 'bar'])->shouldBeCalledTimes(1); |
| 71 | + $attributesProphecy->set('_api_normalization_context', ['foo' => 'bar', 'base_url' => '/api', 'api_gateway' => true])->shouldBeCalledTimes(1); |
| 72 | + $resourceNameCollectionFactoryProphecy = $this->prophesize(ResourceNameCollectionFactoryInterface::class); |
| 73 | + $resourceNameCollectionFactoryProphecy->create()->willReturn(new ResourceNameCollection(['dummies']))->shouldBeCalled(); |
| 74 | + |
| 75 | + $documentation = new DocumentationAction($resourceNameCollectionFactoryProphecy->reveal(), 'my api', '', '1.0.0'); |
| 76 | + $this->assertInstanceOf(Documentation::class, $documentation($requestProphecy->reveal())); |
| 77 | + } |
56 | 78 | }
|
0 commit comments