DiscoveryTest::testDisableAutowiring()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Http\HttplugBundle\Tests\Unit\DependencyInjection\Compiler;
6
7
use Http\Adapter\Guzzle7\Client;
8
use Http\Client\HttpAsyncClient;
9
use Http\Client\HttpClient;
10
use Http\Discovery\HttpClientDiscovery;
11
use Http\HttplugBundle\DependencyInjection\HttplugExtension;
12
use Http\Message\MessageFactory;
13
use Http\Message\StreamFactory;
14
use Http\Message\UriFactory;
15
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
16
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\ContainerBuilderHasAliasConstraint;
17
use PHPUnit\Framework\Constraint\LogicalNot;
18
use Symfony\Component\DependencyInjection\Definition;
19
20
/**
21
 * @author Márk Sági-Kazár <[email protected]>
22
 */
23
final class DiscoveryTest extends AbstractExtensionTestCase
24
{
25
    protected function setUp(): void
26
    {
27
        parent::setUp();
28
29
        $this->setParameter('kernel.debug', true);
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    protected function getContainerExtensions(): array
36
    {
37
        return [
38
            new HttplugExtension(),
39
        ];
40
    }
41
42 View Code Duplication
    public function testDiscoveryFallbacks(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
    {
44
        $this->load();
45
46
        $this->assertContainerBuilderHasService('httplug.client.default', HttpClient::class);
47
        $this->assertContainerBuilderHasService('httplug.message_factory.default', MessageFactory::class);
48
        $this->assertContainerBuilderHasService('httplug.uri_factory.default', UriFactory::class);
49
        $this->assertContainerBuilderHasService('httplug.stream_factory.default', StreamFactory::class);
50
        $this->assertContainerBuilderHasService('httplug.async_client.default', HttpAsyncClient::class);
51
    }
52
53 View Code Duplication
    public function testDiscoveryPartialFallbacks(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        $this->load();
56
        $this->setDefinition('httplug.client.default', new Definition(Client::class));
57
58
        $this->assertContainerBuilderHasService('httplug.client.default', Client::class);
59
        $this->assertContainerBuilderHasService('httplug.message_factory.default', MessageFactory::class);
60
        $this->assertContainerBuilderHasService('httplug.uri_factory.default', UriFactory::class);
61
        $this->assertContainerBuilderHasService('httplug.stream_factory.default', StreamFactory::class);
62
        $this->assertContainerBuilderHasService('httplug.async_client.default', HttpAsyncClient::class);
63
    }
64
65
    public function testNoDiscoveryFallbacks(): void
66
    {
67
        $this->setDefinition('httplug.client.default', new Definition(HttpClient::class));
68
        $this->setDefinition('httplug.message_factory.default', new Definition(MessageFactory::class));
69
        $this->setDefinition('httplug.uri_factory.default', new Definition(UriFactory::class));
70
        $this->setDefinition('httplug.stream_factory.default', new Definition(StreamFactory::class));
71
        $this->setDefinition('httplug.async_client.default', new Definition(HttpAsyncClient::class));
72
73
        $this->load();
74
75
        $this->assertContainerBuilderHasService('httplug.client.default', HttpClient::class);
76
        $clientDefinition = $this->container->getDefinition('httplug.client.default');
77
        $this->assertEquals([HttpClientDiscovery::class, 'find'], $clientDefinition->getFactory());
78
    }
79
80
    public function testEnableAutowiring(): void
81
    {
82
        $this->load([
83
            'default_client_autowiring' => true,
84
        ]);
85
86
        $this->assertContainerBuilderHasService('httplug.client.default');
87
        $this->assertContainerBuilderHasService('httplug.async_client.default');
88
        $this->assertContainerBuilderHasAlias(HttpClient::class);
89
        $this->assertContainerBuilderHasAlias(HttpAsyncClient::class);
90
    }
91
92
    public function testDisableAutowiring(): void
93
    {
94
        if (PHP_VERSION_ID <= 70000) {
95
            $this->markTestSkipped();
96
        }
97
98
        $this->load([
99
            'default_client_autowiring' => false,
100
        ]);
101
102
        $this->assertContainerBuilderHasService('httplug.client.default');
103
        $this->assertContainerBuilderHasService('httplug.async_client.default');
104
105
        self::assertThat(
106
            $this->container,
107
            new LogicalNot(new ContainerBuilderHasAliasConstraint(HttpClient::class))
108
        );
109
        self::assertThat(
110
            $this->container,
111
            new LogicalNot(new ContainerBuilderHasAliasConstraint(HttpAsyncClient::class))
112
        );
113
    }
114
}
115