1
|
|
|
<?php |
2
|
|
|
namespace ElevenLabs\ApiServiceBundle\DependencyInjection; |
3
|
|
|
|
4
|
|
|
use Http\Adapter\Guzzle6\Client; |
5
|
|
|
use Http\Message\MessageFactory\GuzzleMessageFactory; |
6
|
|
|
use Http\Message\UriFactory\GuzzleUriFactory; |
7
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
9
|
|
|
|
10
|
|
|
class ApiServiceExtensionTest extends AbstractExtensionTestCase |
11
|
|
|
{ |
12
|
|
|
protected function setUp() |
13
|
|
|
{ |
14
|
|
|
parent::setUp(); |
15
|
|
|
$this->setParameter('kernel.debug', true); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
protected function getContainerExtensions() |
19
|
|
|
{ |
20
|
|
|
return [new ApiServiceExtension()]; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testConfigLoadDefault() |
24
|
|
|
{ |
25
|
|
|
$this->load(); |
26
|
|
|
|
27
|
|
|
foreach (['uri_factory', 'client', 'message_factory'] as $type) { |
28
|
|
|
$this->assertContainerBuilderHasAlias("api_service.$type", "httplug.$type"); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testItUseHttpPlugServicesByDefault() |
33
|
|
|
{ |
34
|
|
|
// Given services registered by th HTTPlug bundle |
35
|
|
|
$this->container->register('httplug.client', Client::class); |
36
|
|
|
$this->container->register('httplug.message_factory', GuzzleMessageFactory::class); |
37
|
|
|
$this->container->register('httplug.uri_factory', GuzzleUriFactory::class); |
38
|
|
|
|
39
|
|
|
$this->load(); |
40
|
|
|
|
41
|
|
|
$this->assertContainerBuilderHasService('api_service.client', Client::class); |
42
|
|
|
$this->assertContainerBuilderHasService('api_service.message_factory', GuzzleMessageFactory::class); |
43
|
|
|
$this->assertContainerBuilderHasService('api_service.uri_factory', GuzzleUriFactory::class); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testItUseACachedSchemaFactory() |
47
|
|
|
{ |
48
|
|
|
$this->load([ |
49
|
|
|
'cache' => [ |
50
|
|
|
'service' => 'fake.cache.service' |
51
|
|
|
] |
52
|
|
|
]); |
53
|
|
|
|
54
|
|
|
$this->assertContainerBuilderHasAlias( |
55
|
|
|
'api_service.schema_factory', |
56
|
|
|
'api_service.schema_factory.cached_factory' |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testItProvideApiServices() |
61
|
|
|
{ |
62
|
|
|
$this->load([ |
63
|
|
|
'apis' => [ |
64
|
|
|
'foo' => [ |
65
|
|
|
'schema' => '/path/to/schema.json' |
66
|
|
|
] |
67
|
|
|
] |
68
|
|
|
]); |
69
|
|
|
|
70
|
|
|
$this->assertContainerBuilderHasService('api_service.api.foo'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testItProvidePagination() |
74
|
|
|
{ |
75
|
|
|
$this->load([ |
76
|
|
|
'pagination' => [ |
77
|
|
|
'header' => [] |
78
|
|
|
] |
79
|
|
|
]); |
80
|
|
|
|
81
|
|
|
$expectedReference = new Reference('api_service.pagination_provider.chain'); |
82
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
83
|
|
|
'api_service.denormalizer.resource', |
84
|
|
|
0, |
85
|
|
|
$expectedReference |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$expectedReferences = [new Reference('api_service.pagination_provider.header')]; |
89
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
90
|
|
|
'api_service.pagination_provider.chain', |
91
|
|
|
0, |
92
|
|
|
$expectedReferences |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|