1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
||
5 | * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
||
6 | */ |
||
7 | |||
8 | namespace SprykerTest\Glue\DocumentationGeneratorOpenApi\Plugin; |
||
9 | |||
10 | use Codeception\Test\Unit; |
||
11 | use Generated\Shared\Transfer\AnnotationTransfer; |
||
12 | use Generated\Shared\Transfer\ApiApplicationSchemaContextTransfer; |
||
13 | use Generated\Shared\Transfer\ResourceContextTransfer; |
||
14 | use Generated\Shared\Transfer\RestAttributesTransfer; |
||
15 | use Spryker\Glue\DocumentationGeneratorOpenApi\Plugin\DocumentationGeneratorApi\ControllerAnnotationsContextExpanderPlugin; |
||
16 | |||
17 | /** |
||
18 | * Auto-generated group annotations |
||
19 | * |
||
20 | * @group SprykerTest |
||
21 | * @group Glue |
||
22 | * @group DocumentationGeneratorOpenApi |
||
23 | * @group Plugin |
||
24 | * @group ControllerAnnotationsContextExpanderPluginTest |
||
25 | * Add your own group annotations below this line |
||
26 | */ |
||
27 | class ControllerAnnotationsContextExpanderPluginTest extends Unit |
||
28 | { |
||
29 | /** |
||
30 | * @var \SprykerTest\Glue\DocumentationGeneratorOpenApi\DocumentationGeneratorOpenApiCommunicationTester |
||
31 | */ |
||
32 | protected $tester; |
||
33 | |||
34 | /** |
||
35 | * @return void |
||
36 | */ |
||
37 | protected function setUp(): void |
||
38 | { |
||
39 | parent::setUp(); |
||
40 | |||
41 | $this->tester->mockConfigMethod('getAnnotationSourceDirectories', [ |
||
42 | codecept_data_dir() . 'ControllerAnnotationsContextExpanderPluginTest/Glue/%1$s/Controller/', |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
43 | ]); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @return void |
||
48 | */ |
||
49 | public function testCallExpandAndAssertTransferData(): void |
||
50 | { |
||
51 | //Arrange |
||
52 | $resourceContextTransfer = new ResourceContextTransfer(); |
||
53 | $classNameSpace = '\Spryker\Glue\ControllerAnnotationsContextExpanderPluginTest\Controller\TestResourceController'; |
||
54 | $resourceContextTransfer->setController($classNameSpace); |
||
55 | |||
56 | $apiApplicationSchemaContextTransfer = new ApiApplicationSchemaContextTransfer(); |
||
57 | $apiApplicationSchemaContextTransfer->addResourceContext($resourceContextTransfer); |
||
58 | |||
59 | $plugin = new ControllerAnnotationsContextExpanderPlugin(); |
||
60 | $plugin->setFactory($this->tester->getFactory()); |
||
61 | |||
62 | //Act |
||
63 | $apiApplicationSchemaContextTransfer = $plugin->expand($apiApplicationSchemaContextTransfer); |
||
64 | |||
65 | //Assert |
||
66 | $this->assertEquals(1, $apiApplicationSchemaContextTransfer->getResourceContexts()->count()); |
||
67 | $resourceContext = $apiApplicationSchemaContextTransfer->getResourceContexts()[0]; |
||
68 | |||
69 | $this->assertInstanceOf(AnnotationTransfer::class, $resourceContext->getPathAnnotation()->getGetCollection()); |
||
70 | $this->assertEquals(RestAttributesTransfer::class, $resourceContext->getPathAnnotation()->getGetCollection()->getResponseAttributesClassName()); |
||
71 | $this->assertSame(['Retrieves collection of tests.'], $resourceContext->getPathAnnotation()->getGetCollection()->getSummary()); |
||
72 | |||
73 | $this->assertInstanceOf(AnnotationTransfer::class, $resourceContext->getPathAnnotation()->getGetResourceById()); |
||
74 | $this->assertEquals(RestAttributesTransfer::class, $resourceContext->getPathAnnotation()->getGetResourceById()->getResponseAttributesClassName()); |
||
75 | $this->assertSame(['Retrieves store by id.'], $resourceContext->getPathAnnotation()->getGetResourceById()->getSummary()); |
||
76 | $this->assertSame(['404' => 'Test not found.'], $resourceContext->getPathAnnotation()->getGetResourceById()->getResponses()); |
||
77 | } |
||
78 | } |
||
79 |