MappingStepSpec::it_processes_an_item()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace spec\Port\Steps\Step;
4
5
use Port\Steps\Step;
6
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
7
use PhpSpec\ObjectBehavior;
8
9
class MappingStepSpec extends ObjectBehavior
10
{
11
    function let(PropertyAccessorInterface $propertyAccessor)
12
    {
13
        $this->beConstructedWith([], $propertyAccessor);
14
    }
15
16
    function it_is_initializable()
17
    {
18
        $this->shouldHaveType('Port\Steps\Step\MappingStep');
19
    }
20
21
    function it_is_a_step()
22
    {
23
        $this->shouldHaveType('Port\Steps\Step');
24
    }
25
26
    function it_processes_an_item(Step $step, PropertyAccessorInterface $propertyAccessor)
27
    {
28
        $next = function() {};
29
        // We cannot mock behavior by reference
30
        $item = ['foo' => true, 'bar' => true];
31
        $item2 = ['bar' => true];
32
        $step->process($item2, $next)->willReturn(true);
33
        $propertyAccessor->getValue($item, 'foo')->willReturn(true);
34
        $propertyAccessor->setValue($item, 'bar', true)->shouldBeCalled();
35
36
        $this->map('foo', 'bar')->shouldReturn($this);
37
38
        $this->process(
0 ignored issues
show
Bug introduced by
The method process() does not exist on spec\Port\Steps\Step\MappingStepSpec. Did you maybe mean it_processes_an_item()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
39
            $item,
40
            function($item) use ($step, $next) {
41
                return $step->process($item, $next);
42
            }
43
        );
44
    }
45
46 View Code Duplication
    function it_throws_a_mapping_exception_when_no_property_is_found(Step $step, PropertyAccessorInterface $propertyAccessor)
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...
47
    {
48
        $next = function() {};
49
        // We cannot mock behavior by reference
50
        $item = ['foo' => true, 'bar' => true];
51
        $item2 = ['bar' => true];
52
        $step->process($item2, $next)->shouldNotBeCalled();
53
        $propertyAccessor->getValue($item, 'foo')->willThrow('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
54
        $propertyAccessor->setValue($item, 'bar', true)->shouldNotBeCalled();
55
56
        $this->map('foo', 'bar')->shouldReturn($this);
57
58
        $this->shouldThrow('Port\Exception\MappingException')->duringProcess(
59
            $item,
60
            function($item) use ($step, $next) {
61
                return $step->process($item, $next);
62
            }
63
        );
64
    }
65
66 View Code Duplication
    function it_throws_a_mapping_exception_when_the_type_is_unexpected(Step $step, PropertyAccessorInterface $propertyAccessor)
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...
67
    {
68
        $next = function() {};
69
        // We cannot mock behavior by reference
70
        $item = ['foo' => true, 'bar' => true];
71
        $item2 = ['bar' => true];
72
        $step->process($item2, $next)->shouldNotBeCalled();
73
        $propertyAccessor->getValue($item, 'foo')->willThrow('Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException');
74
        $propertyAccessor->setValue($item, 'bar', true)->shouldNotBeCalled();
75
76
        $this->map('foo', 'bar')->shouldReturn($this);
77
78
        $this->shouldThrow('Port\Exception\MappingException')->duringProcess(
79
            $item,
80
            function($item) use ($step, $next) {
81
                return $step->process($item, $next);
82
            }
83
        );
84
    }
85
}
86