Completed
Push — develop ( 9f43d2...2581dc )
by Filipe
01:49
created

ContainerBuilderSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 29.79 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 14
loc 47
rs 10
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace spec\Slick\Di;
4
5
use Slick\Di\ContainerInterface;
6
use Slick\Di\ContainerAwareInterface;
7
use Slick\Di\ContainerBuilder;
8
use PhpSpec\ObjectBehavior;
9
use Prophecy\Argument;
10
11
class ContainerBuilderSpec extends ObjectBehavior
12
{
13
    function it_is_initializable()
14
    {
15
        $this->shouldHaveType(ContainerBuilder::class);
16
    }
17
18
    function its_container_aware()
19
    {
20
        $this->shouldBeAnInstanceOf(ContainerAwareInterface::class);
21
    }
22
23
    function it_creates_empty_containers()
24
    {
25
        $this->beConstructedWith();
26
        $this->getContainer()->shouldBeAnInstanceOf(ContainerInterface::class);
27
    }
28
29
    function it_hydrates_a_container_with_an_array_of_definitions(ContainerInterface $container)
30
    {
31
        $services = [
32
            'foo' => 'bar',
33
            'baz' => '@foo'
34
        ];
35
        $container->register(Argument::type('string'), Argument::any())->shouldBeCalledTimes(2);
36
        $this->beConstructedWith($services);
37
        $this->setContainer($container);
38
        $this->getContainer()->shouldBeAnInstanceOf(ContainerInterface::class);
39
    }
40
41
    function it_hydrates_a_container_with_an_array_from_a_file(ContainerInterface $container)
42
    {
43
        $container->register(Argument::type('string'), Argument::any())->shouldBeCalledTimes(3);
44
        $this->beConstructedWith(__DIR__ .'/services/services1.php');
45
        $this->setContainer($container);
46
        $this->getContainer()->shouldBeAnInstanceOf(ContainerInterface::class);
47
    }
48
49
    function it_hydrates_a_container_with_all_arrays_form_the_files_within_a_directory(ContainerInterface $container)
50
    {
51
        $container->register(Argument::type('string'), Argument::any())->shouldBeCalledTimes(6);
52
        $this->beConstructedWith(__DIR__ .'/services');
53
        $this->setContainer($container);
54
        $this->getContainer()->shouldBeAnInstanceOf(ContainerInterface::class);
55
    }
56
57
}
58