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
|
|
View Code Duplication |
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
|
|
View Code Duplication |
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
|
|
|
|
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.