1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace tests\Happyr\DoctrineSpecification\Operand; |
4
|
|
|
|
5
|
|
|
use Happyr\DoctrineSpecification\Operand\ArgumentToOperandConverter; |
6
|
|
|
use Happyr\DoctrineSpecification\Operand\Field; |
7
|
|
|
use Happyr\DoctrineSpecification\Operand\Operand; |
8
|
|
|
use Happyr\DoctrineSpecification\Operand\Value; |
9
|
|
|
use PhpSpec\ObjectBehavior; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @mixin ArgumentToOperandConverter |
13
|
|
|
*/ |
14
|
|
|
class ArgumentToOperandConverterSpec extends ObjectBehavior |
15
|
|
|
{ |
16
|
|
|
public function it_is_a_converter() |
17
|
|
|
{ |
18
|
|
|
$this->shouldBeAnInstanceOf('Happyr\DoctrineSpecification\Operand\ArgumentToOperandConverter'); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function it_not_convert_operand_to_field(Operand $operand) |
22
|
|
|
{ |
23
|
|
|
$this->toField($operand)->shouldReturn($operand); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function it_convert_argument_to_field() |
27
|
|
|
{ |
28
|
|
|
$this->toField('foo')->shouldBeAnInstanceOf('Happyr\DoctrineSpecification\Operand\Field'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function it_not_convert_operand_to_value(Operand $operand) |
32
|
|
|
{ |
33
|
|
|
$this->toValue($operand)->shouldReturn($operand); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function it_convert_argument_to_value() |
37
|
|
|
{ |
38
|
|
|
$this->toValue('foo')->shouldBeAnInstanceOf('Happyr\DoctrineSpecification\Operand\Value'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function it_is_all_arguments_a_operands(Operand $first, Operand $second) |
42
|
|
|
{ |
43
|
|
|
$arguments = array($first, $second); |
44
|
|
|
$this->isAllOperands($arguments)->shouldReturn(true); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function it_is_not_all_arguments_a_operands(Operand $first, Operand $second) |
48
|
|
|
{ |
49
|
|
|
$arguments = array($first, 'foo', $second); |
50
|
|
|
$this->isAllOperands($arguments)->shouldReturn(false); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function it_no_nothing_to_convert() |
54
|
|
|
{ |
55
|
|
|
$this->convert(array())->shouldReturn([]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function it_a_convertible_field() |
59
|
|
|
{ |
60
|
|
|
$subject = $this->convert(array('foo')); |
61
|
|
|
$subject->shouldBeArray(); |
62
|
|
|
$subject->shouldHaveCount(1); |
63
|
|
|
$subject->shouldHaveField(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function it_a_already_converted_field(Operand $field) |
67
|
|
|
{ |
68
|
|
|
$this->convert(array($field))->shouldReturn(array($field)); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function it_a_convertible_field_and_value() |
72
|
|
|
{ |
73
|
|
|
$subject = $this->convert(array('foo', 'bar')); |
74
|
|
|
$subject->shouldBeArray(); |
75
|
|
|
$subject->shouldHaveCount(2); |
76
|
|
|
$subject->shouldHaveField(); |
77
|
|
|
$subject->shouldHaveValue(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function it_a_already_converted_value(Operand $field, Operand $value) |
81
|
|
|
{ |
82
|
|
|
$this->convert(array($field, $value))->shouldReturn(array($field, $value)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function it_a_already_converted_value2(Operand $value) |
86
|
|
|
{ |
87
|
|
|
$subject = $this->convert(array('foo', $value)); |
88
|
|
|
$subject->shouldBeArray(); |
89
|
|
|
$subject->shouldHaveCount(2); |
90
|
|
|
$subject->shouldHaveField(); |
91
|
|
|
$subject->shouldHaveOperandAt(1); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function it_a_convertible_arguments(Operand $first, Operand $second) |
95
|
|
|
{ |
96
|
|
|
$subject = $this->convert(array('foo', $first, $second, 'bar')); |
97
|
|
|
$subject->shouldBeArray(); |
98
|
|
|
$subject->shouldHaveCount(4); |
99
|
|
|
$subject->shouldHaveField(); |
100
|
|
|
$subject->shouldHaveValue(); |
101
|
|
|
$subject->shouldHaveOperandAt(1); |
102
|
|
|
$subject->shouldHaveOperandAt(2); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function it_is_not_convertible_arguments(Field $field, Operand $operand, Value $value) |
106
|
|
|
{ |
107
|
|
|
$this->shouldThrow('Happyr\DoctrineSpecification\Exception\NotConvertibleException') |
108
|
|
|
->duringConvert(array($field, $operand, 'foo', $value)); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function getMatchers() |
112
|
|
|
{ |
113
|
|
|
return array( |
114
|
|
|
'haveField' => function ($subject) { |
115
|
|
|
return $subject[0] instanceof Field; |
116
|
|
|
}, |
117
|
|
|
'haveValue' => function ($subject) { |
118
|
|
|
return $subject[count($subject) - 1] instanceof Value; |
119
|
|
|
}, |
120
|
|
|
'haveOperandAt' => function ($subject, $position) { |
121
|
|
|
return $subject[$position] instanceof Operand; |
122
|
|
|
}, |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|