it_gets_parameters_from_not_frozen_container()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the CrossContainerExtension package.
7
 *
8
 * (c) Kamil Kokot <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace spec\FriendsOfBehat\CrossContainerExtension;
15
16
use FriendsOfBehat\CrossContainerExtension\ContainerAccessor;
17
use PhpSpec\ObjectBehavior;
18
use Symfony\Component\DependencyInjection\Container;
19
use Symfony\Component\DependencyInjection\ContainerInterface;
20
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
21
use Symfony\Component\HttpKernel\KernelInterface;
22
23
final class KernelBasedContainerAccessorSpec extends ObjectBehavior
24
{
25
    function let(KernelInterface $kernel, ContainerInterface $container): void
26
    {
27
        $this->beConstructedWith($kernel);
28
29
        $container->has('test.service_container')->willReturn(false);
30
    }
31
32
    function it_is_a_container_accessor(): void
33
    {
34
        $this->shouldImplement(ContainerAccessor::class);
35
    }
36
37
    function it_uses_test_container_if_available(KernelInterface $kernel, ContainerInterface $container, ContainerInterface $testContainer)
38
    {
39
        $kernel->getContainer()->willReturn($container);
40
        $container->has('test.service_container')->shouldBeCalled()->willReturn(true);
41
42
        $service = new \stdClass();
43
        $testContainer->get('acme')->willReturn($service);
44
        $testContainer->has('acme')->willReturn(true);
45
46
        $container->get('test.service_container')->shouldBeCalled()->willReturn($testContainer);
47
48
        $this->getService('acme')->shouldReturn($service);
49
    }
50
51
    function it_gets_a_service(KernelInterface $kernel, ContainerInterface $container): void
52
    {
53
        $service = new \stdClass();
54
55
        $kernel->getContainer()->willReturn($container);
56
        $container->get('acme')->willReturn($service);
57
        $container->has('acme')->willReturn(true);
58
59
        $this->getService('acme')->shouldReturn($service);
60
    }
61
62
    function it_throws_an_exception_if_could_not_get_service(KernelInterface $kernel, ContainerInterface $container): void
63
    {
64
        $kernel->getContainer()->willReturn($container);
65
        $container->has('acme')->willReturn(false);
66
67
        $this->shouldThrow(\DomainException::class)->during('getService', ['acme']);
68
    }
69
70 View Code Duplication
    function it_gets_parameters_from_frozen_container(KernelInterface $kernel, Container $container): 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...
71
    {
72
        $kernel->getContainer()->willReturn($container);
73
74
        $container->isCompiled()->willReturn(true);
75
        $container->getParameterBag()->willReturn(new ParameterBag(['name' => 'value']));
76
77
        $this->getParameters()->shouldReturn(['name' => 'value']);
78
    }
79
80 View Code Duplication
    function it_gets_parameters_from_not_frozen_container(KernelInterface $kernel, Container $container): 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...
81
    {
82
        $kernel->getContainer()->willReturn($container);
83
84
        $container->isCompiled()->willReturn(false);
85
        $container->getParameterBag()->willReturn(new ParameterBag(['name' => 'value']));
86
87
        $this->getParameters()->shouldReturn(['name' => 'value']);
88
    }
89
90
    function it_throws_an_exception_if_could_not_get_parameters(KernelInterface $kernel, ContainerInterface $container): void
91
    {
92
        $kernel->getContainer()->willReturn($container);
93
94
        $this->shouldThrow(\DomainException::class)->during('getParameters');
95
    }
96
}
97