|
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( |
|
|
|
|
|
|
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) |
|
|
|
|
|
|
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) |
|
|
|
|
|
|
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
|
|
|
|
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.