1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the CrossContainerExtension package. |
5
|
|
|
* |
6
|
|
|
* (c) Kamil Kokot <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace spec\FriendsOfBehat\CrossContainerExtension; |
13
|
|
|
|
14
|
|
|
use FriendsOfBehat\CrossContainerExtension\ContainerAccessor; |
15
|
|
|
use PhpSpec\ObjectBehavior; |
16
|
|
|
use Symfony\Component\DependencyInjection\Container; |
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
18
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
19
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
20
|
|
|
|
21
|
|
|
final class KernelBasedContainerAccessorSpec extends ObjectBehavior |
22
|
|
|
{ |
23
|
|
|
function let(KernelInterface $kernel) |
24
|
|
|
{ |
25
|
|
|
$this->beConstructedWith($kernel); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
function it_is_a_container_accessor() |
29
|
|
|
{ |
30
|
|
|
$this->shouldImplement(ContainerAccessor::class); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_gets_a_service(KernelInterface $kernel, ContainerInterface $container) |
34
|
|
|
{ |
35
|
|
|
$service = new \stdClass(); |
36
|
|
|
|
37
|
|
|
$kernel->getContainer()->willReturn($container); |
38
|
|
|
$container->get('acme')->willReturn($service); |
39
|
|
|
|
40
|
|
|
$this->getService('acme')->shouldReturn($service); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function it_gets_parameters(KernelInterface $kernel, Container $container) |
44
|
|
|
{ |
45
|
|
|
$kernel->getContainer()->willReturn($container); |
46
|
|
|
$container->getParameterBag()->willReturn(new ParameterBag(['name' => 'value'])); |
47
|
|
|
|
48
|
|
|
$this->getParameters()->shouldReturn(['name' => 'value']); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
function it_throws_an_exception_if_could_not_get_parameters(KernelInterface $kernel, ContainerInterface $container) |
52
|
|
|
{ |
53
|
|
|
$kernel->getContainer()->willReturn($container); |
54
|
|
|
|
55
|
|
|
$this->shouldThrow(\DomainException::class)->during('getParameters'); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|