Completed
Branch develop (9f43d2)
by Filipe
05:14
created

ConstructorObject   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setOther() 0 4 1
1
<?php
2
3
namespace spec\Slick\Di\Definition\Object;
4
5
use Slick\Di\ContainerInterface;
6
use Slick\Di\Definition\Object\DefinitionData;
7
use Slick\Di\Definition\Object\Resolver;
8
use Slick\Di\Definition\Object\ResolverInterface;
9
use PhpSpec\ObjectBehavior;
10
use Prophecy\Argument;
11
12
class ResolverSpec extends ObjectBehavior
13
{
14
    function it_is_initializable()
15
    {
16
        $this->shouldHaveType(Resolver::class);
17
    }
18
19
    function its_a_resolver()
20
    {
21
        $this->shouldBeAnInstanceOf(ResolverInterface::class);
22
    }
23
24
    function it_resolves_simple_objects()
25
    {
26
        $data = new DefinitionData(SimpleObject::class);
27
        $this->resolve($data)->shouldBeAnInstanceOf(SimpleObject::class);
28
    }
29
30
    function it_resolvers_objects_with_constructor_dependencies(ContainerInterface $container)
31
    {
32
        $object = new SimpleObject();
33
        $container->get('first-object')->willReturn($object);
34
        $this->setContainer($container);
35
        $data = new DefinitionData(ConstructorObject::class, ['@first-object', 'test']);
36
        $this->resolve($data)->shouldBeAnInstanceOf(ConstructorObject::class);
37
    }
38
39 View Code Duplication
    function it_can_call_methods_with_arguments_on_resolved_objects(ContainerInterface $container, SimpleObject $object)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
40
    {
41
        $container->get('first-object')->willReturn($object);
42
        $this->setContainer($container);
43
        $data = new DefinitionData(ConstructorObject::class, ['@first-object']);
44
        $data->addCall(DefinitionData::METHOD, 'setOther', ['@first-object']);
45
        $this->resolve($data)->shouldHavePropertyEquals('other', $object);
46
    }
47
48 View Code Duplication
    function it_can_assign_property_values_on_resolved_objects(ContainerInterface $container, SimpleObject $object)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
49
    {
50
        $container->get('first-object')->willReturn($object);
51
        $this->setContainer($container);
52
        $data = new DefinitionData(ConstructorObject::class, ['@first-object']);
53
        $data->addCall(DefinitionData::PROPERTY, 'other', '@first-object');
54
        $this->resolve($data)->shouldHavePropertyEquals('other', $object);
55
    }
56
57
    function it_creates_object_from_classes_without_constructor()
58
    {
59
        $data = new DefinitionData(WithoutConstructor::class);
60
        $this->resolve($data)->shouldBeAnInstanceOf(WithoutConstructor::class);
61
62
    }
63
64
    public function getMatchers()
65
    {
66
        return [
67
            'havePropertyEquals' => function(ConstructorObject $subject, $property, $expected) {
68
                \PHPUnit_Framework_Assert::assertEquals($expected, $subject->{$property});
69
                return true;
70
            }
71
        ];
72
    }
73
}
74
75
76
class SimpleObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
77
{
78
}
79
80
class ConstructorObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
81
{
82
    /**
83
     * @var SimpleObject
84
     */
85
    private $object;
86
87
    /**
88
     * @var null
89
     */
90
    public $other;
91
92
    public function __construct(SimpleObject $object, $other = null)
93
    {
94
        $this->object = $object;
95
        $this->other = $other;
96
    }
97
98
    public function setOther($value)
99
    {
100
        $this->other = $value;
101
    }
102
}
103
104
class WithoutConstructor
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
105
{
106
107
}