Completed
Push — master ( 4a56cb...a5ac8e )
by Sam
05:43
created

CompositeContainerSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 43
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 5 1
A it_is_psr11_compliant() 0 4 1
A it_can_tell_if_it_has_a_service() 0 11 1
A it_can_get_a_service() 0 9 1
A it_throws_an_exception_if_you_try_to_get_a_service_it_doesnt_have() 0 7 1
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