1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace UltraLiteSpec\UltraLite\CompositeContainer; |
4
|
|
|
|
5
|
|
|
use Psr\Container\ContainerInterface; |
6
|
|
|
use Psr\Container\NotFoundExceptionInterface; |
7
|
|
|
use UltraLite\CompositeContainer\CompositeContainer; |
8
|
|
|
use PhpSpec\ObjectBehavior; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @mixin CompositeContainer |
12
|
|
|
*/ |
13
|
|
|
class CompositeContainerSpec extends ObjectBehavior |
14
|
|
|
{ |
15
|
|
|
function let(ContainerInterface $container1, ContainerInterface $container2) |
16
|
|
|
{ |
17
|
|
|
$this->addContainer($container1); |
18
|
|
|
$this->addContainer($container2); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
function it_is_psr11_compliant() |
22
|
|
|
{ |
23
|
|
|
$this->shouldBeAnInstanceOf(ContainerInterface::class); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
function it_can_tell_if_it_has_a_service(ContainerInterface $container1, ContainerInterface $container2) |
27
|
|
|
{ |
28
|
|
|
$container1->has('service-id-1')->willReturn(false); |
29
|
|
|
$container2->has('service-id-1')->willReturn(true); |
30
|
|
|
|
31
|
|
|
$container1->has('service-id-2')->willReturn(false); |
32
|
|
|
$container2->has('service-id-2')->willReturn(false); |
33
|
|
|
|
34
|
|
|
$this->has('service-id-1')->shouldBe(true); |
35
|
|
|
$this->has('service-id-2')->shouldBe(false); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function it_can_get_a_service(ContainerInterface $container1, ContainerInterface $container2, \stdClass $service) |
39
|
|
|
{ |
40
|
|
|
$container1->has('service-id')->willReturn(false); |
41
|
|
|
$container2->has('service-id')->willReturn(true); |
42
|
|
|
|
43
|
|
|
$container2->get('service-id')->willReturn($service); |
44
|
|
|
|
45
|
|
|
$this->get('service-id')->shouldBe($service); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
function it_throws_an_exception_if_you_try_to_get_a_service_it_doesnt_have(ContainerInterface $container1, ContainerInterface $container2) |
49
|
|
|
{ |
50
|
|
|
$container1->has('service-id')->willReturn(false); |
51
|
|
|
$container2->has('service-id')->willReturn(false); |
52
|
|
|
|
53
|
|
|
$this->shouldThrow(NotFoundExceptionInterface::class)->during('get', ['service-id']); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
function it_treats_the_first_container_as_higher_priority( |
57
|
|
|
ContainerInterface $container1, |
58
|
|
|
ContainerInterface $container2, |
59
|
|
|
\stdClass $service1, |
60
|
|
|
\stdClass $service2) |
61
|
|
|
{ |
62
|
|
|
$container1->has('service-id')->willReturn(true); |
63
|
|
|
$container2->has('service-id')->willReturn(true); |
64
|
|
|
|
65
|
|
|
$container1->get('service-id')->willReturn($service1); |
66
|
|
|
$container2->get('service-id')->willReturn($service2); |
67
|
|
|
|
68
|
|
|
$this->get('service-id')->shouldBe($service1); |
69
|
|
|
$this->get('service-id')->shouldNotBe($service2); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|