1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ElevenLabs\ApiServiceBundle\Tests\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use ElevenLabs\ApiServiceBundle\DependencyInjection\ApiServiceExtension; |
6
|
|
|
use Http\Adapter\Guzzle6\Client; |
7
|
|
|
use Http\Message\MessageFactory\GuzzleMessageFactory; |
8
|
|
|
use Http\Message\UriFactory\GuzzleUriFactory; |
9
|
|
|
use JsonSchema\Validator; |
10
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
11
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
12
|
|
|
use Symfony\Component\Serializer\Encoder\ChainDecoder; |
13
|
|
|
|
14
|
|
|
class ApiServiceExtensionTest extends AbstractExtensionTestCase |
15
|
|
|
{ |
16
|
|
|
protected function setUp() |
17
|
|
|
{ |
18
|
|
|
parent::setUp(); |
19
|
|
|
$this->setParameter('kernel.debug', true); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
protected function getContainerExtensions() |
23
|
|
|
{ |
24
|
|
|
return [new ApiServiceExtension()]; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testConfigLoadDefault() |
28
|
|
|
{ |
29
|
|
|
$this->load(); |
30
|
|
|
|
31
|
|
|
foreach (['uri_factory', 'client', 'message_factory'] as $type) { |
32
|
|
|
$this->assertContainerBuilderHasAlias("api_service.$type", "httplug.$type"); |
33
|
|
|
} |
34
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
35
|
|
|
'api_service.denormalizer.resource', |
36
|
|
|
0, |
37
|
|
|
null |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testItUseHttpPlugServicesByDefault() |
42
|
|
|
{ |
43
|
|
|
// Given services registered by th HTTPlug bundle |
44
|
|
|
$this->container->register('httplug.client', Client::class); |
45
|
|
|
$this->container->register('httplug.message_factory', GuzzleMessageFactory::class); |
46
|
|
|
$this->container->register('httplug.uri_factory', GuzzleUriFactory::class); |
47
|
|
|
|
48
|
|
|
$this->load(); |
49
|
|
|
|
50
|
|
|
$this->assertContainerBuilderHasService('api_service.client', Client::class); |
51
|
|
|
$this->assertContainerBuilderHasService('api_service.message_factory', GuzzleMessageFactory::class); |
52
|
|
|
$this->assertContainerBuilderHasService('api_service.uri_factory', GuzzleUriFactory::class); |
53
|
|
|
$this->assertContainerBuilderHasService('api_service.decoder.symfony', ChainDecoder::class); |
54
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
55
|
|
|
'api_service.decoder', |
56
|
|
|
0, |
57
|
|
|
new Reference('api_service.decoder.symfony') |
58
|
|
|
); |
59
|
|
|
$this->assertContainerBuilderHasService('api_service.json_schema_validator', Validator::class); |
60
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
61
|
|
|
'api_service.denormalizer.resource', |
62
|
|
|
0, |
63
|
|
|
null |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testItUseACachedSchemaFactory() |
68
|
|
|
{ |
69
|
|
|
$this->load([ |
70
|
|
|
'cache' => [ |
71
|
|
|
'service' => 'fake.cache.service' |
72
|
|
|
] |
73
|
|
|
]); |
74
|
|
|
|
75
|
|
|
$this->assertContainerBuilderHasAlias( |
76
|
|
|
'api_service.schema_factory', |
77
|
|
|
'api_service.schema_factory.cached_factory' |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
$this->assertContainerBuilderHasAlias('api_service.serializer', 'serializer'); |
81
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
82
|
|
|
'api_service.denormalizer.resource', |
83
|
|
|
0, |
84
|
|
|
null |
85
|
|
|
); |
86
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
87
|
|
|
'api_service.schema_factory.cached_factory', |
88
|
|
|
0, |
89
|
|
|
new Reference('fake.cache.service') |
90
|
|
|
); |
91
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
92
|
|
|
'api_service.schema_factory.cached_factory', |
93
|
|
|
1, |
94
|
|
|
new Reference('api_service.schema_factory.swagger') |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testItProvideApiServices() |
99
|
|
|
{ |
100
|
|
|
$this->load([ |
101
|
|
|
'apis' => [ |
102
|
|
|
'foo' => [ |
103
|
|
|
'schema' => '/path/to/schema.json' |
104
|
|
|
] |
105
|
|
|
] |
106
|
|
|
]); |
107
|
|
|
|
108
|
|
|
$this->assertContainerBuilderHasService('api_service.api.foo'); |
109
|
|
|
$this->assertContainerBuilderHasAlias('api_service.serializer', 'serializer'); |
110
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
111
|
|
|
'api_service.denormalizer.resource', |
112
|
|
|
0, |
113
|
|
|
null |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function testItProvidePagination() |
118
|
|
|
{ |
119
|
|
|
$this->load([ |
120
|
|
|
'pagination' => [ |
121
|
|
|
'header' => [] |
122
|
|
|
] |
123
|
|
|
]); |
124
|
|
|
|
125
|
|
|
$expectedReference = new Reference('api_service.pagination_provider.chain'); |
126
|
|
|
$this->assertContainerBuilderHasAlias('api_service.serializer', 'serializer'); |
127
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
128
|
|
|
'api_service.denormalizer.resource', |
129
|
|
|
0, |
130
|
|
|
$expectedReference |
131
|
|
|
); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|