1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Http\HttplugBundle\Tests\Unit\DependencyInjection\Compiler; |
4
|
|
|
|
5
|
|
|
use Http\Client\HttpAsyncClient; |
6
|
|
|
use Http\Client\HttpClient; |
7
|
|
|
use Http\Discovery\HttpClientDiscovery; |
8
|
|
|
use Http\HttplugBundle\DependencyInjection\HttplugExtension; |
9
|
|
|
use Http\Message\MessageFactory; |
10
|
|
|
use Http\Message\StreamFactory; |
11
|
|
|
use Http\Message\UriFactory; |
12
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
13
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @author Márk Sági-Kazár <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
final class DiscoveryTest extends AbstractExtensionTestCase |
19
|
|
|
{ |
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
parent::setUp(); |
23
|
|
|
|
24
|
|
|
$this->setParameter('kernel.debug', true); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
|
|
protected function getContainerExtensions() |
31
|
|
|
{ |
32
|
|
|
return [ |
33
|
|
|
new HttplugExtension(), |
34
|
|
|
]; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testDiscoveryFallbacks() |
38
|
|
|
{ |
39
|
|
|
$this->load(); |
40
|
|
|
|
41
|
|
|
$this->assertContainerBuilderHasService('httplug.client.default', HttpClient::class); |
42
|
|
|
$this->assertContainerBuilderHasService('httplug.message_factory.default', MessageFactory::class); |
43
|
|
|
$this->assertContainerBuilderHasService('httplug.uri_factory.default', UriFactory::class); |
44
|
|
|
$this->assertContainerBuilderHasService('httplug.stream_factory.default', StreamFactory::class); |
45
|
|
|
$this->assertContainerBuilderHasService('httplug.async_client.default', HttpAsyncClient::class); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testDiscoveryPartialFallbacks() |
49
|
|
|
{ |
50
|
|
|
$this->load(); |
51
|
|
|
$this->setDefinition('httplug.client.default', new Definition('Http\Adapter\Guzzle6\Client')); |
52
|
|
|
|
53
|
|
|
$this->assertContainerBuilderHasService('httplug.client.default', 'Http\Adapter\Guzzle6\Client'); |
54
|
|
|
$this->assertContainerBuilderHasService('httplug.message_factory.default', MessageFactory::class); |
55
|
|
|
$this->assertContainerBuilderHasService('httplug.uri_factory.default', UriFactory::class); |
56
|
|
|
$this->assertContainerBuilderHasService('httplug.stream_factory.default', StreamFactory::class); |
57
|
|
|
$this->assertContainerBuilderHasService('httplug.async_client.default', HttpAsyncClient::class); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testNoDiscoveryFallbacks() |
61
|
|
|
{ |
62
|
|
|
$this->setDefinition('httplug.client.default', new Definition(HttpClient::class)); |
63
|
|
|
$this->setDefinition('httplug.message_factory.default', new Definition(MessageFactory::class)); |
64
|
|
|
$this->setDefinition('httplug.uri_factory.default', new Definition(UriFactory::class)); |
65
|
|
|
$this->setDefinition('httplug.stream_factory.default', new Definition(StreamFactory::class)); |
66
|
|
|
$this->setDefinition('httplug.async_client.default', new Definition(HttpAsyncClient::class)); |
67
|
|
|
|
68
|
|
|
$this->load(); |
69
|
|
|
|
70
|
|
|
$this->assertContainerBuilderHasService('httplug.client.default', HttpClient::class); |
71
|
|
|
$clientDefinition = $this->container->getDefinition('httplug.client.default'); |
72
|
|
|
$this->assertEquals([HttpClientDiscovery::class, 'find'], $clientDefinition->getFactory()); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|