Completed
Push — master ( aed7e5...5044b6 )
by David
03:29 queued 11s
created

tests/Functional/DiscoveryTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 Matthias\SymfonyDependencyInjectionTest\PhpUnit\ContainerBuilderHasAliasConstraint;
14
use PHPUnit\Framework\Constraint\LogicalNot;
15
use Symfony\Component\DependencyInjection\Definition;
16
use Http\Adapter\Guzzle6\Client;
17
18
/**
19
 * @author Márk Sági-Kazár <[email protected]>
20
 */
21
final class DiscoveryTest extends AbstractExtensionTestCase
22
{
23
    protected function setUp()
24
    {
25
        parent::setUp();
26
27
        $this->setParameter('kernel.debug', true);
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected function getContainerExtensions()
34
    {
35
        return [
36
            new HttplugExtension(),
37
        ];
38
    }
39
40 View Code Duplication
    public function testDiscoveryFallbacks()
0 ignored issues
show
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...
41
    {
42
        $this->load();
43
44
        $this->assertContainerBuilderHasService('httplug.client.default', HttpClient::class);
45
        $this->assertContainerBuilderHasService('httplug.message_factory.default', MessageFactory::class);
46
        $this->assertContainerBuilderHasService('httplug.uri_factory.default', UriFactory::class);
47
        $this->assertContainerBuilderHasService('httplug.stream_factory.default', StreamFactory::class);
48
        $this->assertContainerBuilderHasService('httplug.async_client.default', HttpAsyncClient::class);
49
    }
50
51 View Code Duplication
    public function testDiscoveryPartialFallbacks()
0 ignored issues
show
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...
52
    {
53
        $this->load();
54
        $this->setDefinition('httplug.client.default', new Definition(Client::class));
55
56
        $this->assertContainerBuilderHasService('httplug.client.default', Client::class);
57
        $this->assertContainerBuilderHasService('httplug.message_factory.default', MessageFactory::class);
58
        $this->assertContainerBuilderHasService('httplug.uri_factory.default', UriFactory::class);
59
        $this->assertContainerBuilderHasService('httplug.stream_factory.default', StreamFactory::class);
60
        $this->assertContainerBuilderHasService('httplug.async_client.default', HttpAsyncClient::class);
61
    }
62
63
    public function testNoDiscoveryFallbacks()
64
    {
65
        $this->setDefinition('httplug.client.default', new Definition(HttpClient::class));
66
        $this->setDefinition('httplug.message_factory.default', new Definition(MessageFactory::class));
67
        $this->setDefinition('httplug.uri_factory.default', new Definition(UriFactory::class));
68
        $this->setDefinition('httplug.stream_factory.default', new Definition(StreamFactory::class));
69
        $this->setDefinition('httplug.async_client.default', new Definition(HttpAsyncClient::class));
70
71
        $this->load();
72
73
        $this->assertContainerBuilderHasService('httplug.client.default', HttpClient::class);
74
        $clientDefinition = $this->container->getDefinition('httplug.client.default');
75
        $this->assertEquals([HttpClientDiscovery::class, 'find'], $clientDefinition->getFactory());
76
    }
77
78
    public function testEnableAutowiring()
79
    {
80
        $this->load([
81
            'default_client_autowiring' => true,
82
        ]);
83
84
        $this->assertContainerBuilderHasService('httplug.client.default');
85
        $this->assertContainerBuilderHasService('httplug.async_client.default');
86
        $this->assertContainerBuilderHasAlias(HttpClient::class);
87
        $this->assertContainerBuilderHasAlias(HttpAsyncClient::class);
88
    }
89
90
    public function testDisableAutowiring()
91
    {
92
        if (PHP_VERSION_ID <= 70000) {
93
            $this->markTestSkipped();
94
        }
95
96
        $this->load([
97
            'default_client_autowiring' => false,
98
        ]);
99
100
        $this->assertContainerBuilderHasService('httplug.client.default');
101
        $this->assertContainerBuilderHasService('httplug.async_client.default');
102
103
        self::assertThat(
104
            $this->container,
105
            new LogicalNot(new ContainerBuilderHasAliasConstraint(HttpClient::class))
106
        );
107
        self::assertThat(
108
            $this->container,
109
            new LogicalNot(new ContainerBuilderHasAliasConstraint(HttpAsyncClient::class))
110
        );
111
    }
112
}
113