|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PHPKitchen\CodeSpecs\Expectation\Matcher; |
|
4
|
|
|
|
|
5
|
|
|
use PHPKitchen\CodeSpecs\Expectation\Matcher\Base\Matcher; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* ValueMatcher is designed to check given value matches expectation. |
|
9
|
|
|
* |
|
10
|
|
|
* @package PHPKitchen\CodeSpecs\Expectation |
|
11
|
|
|
* @author Dima Kolodko <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class ValueMatcher extends Matcher { |
|
14
|
|
|
/** |
|
15
|
|
|
* @return $this |
|
16
|
|
|
*/ |
|
17
|
|
|
public function isInternalType($type): self { |
|
18
|
|
|
$this->startStep('is internal type "' . $type . '"') |
|
19
|
|
|
->assertInternalType($type); |
|
20
|
|
|
|
|
21
|
|
|
return $this; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @return $this |
|
26
|
|
|
*/ |
|
27
|
|
|
public function isNotInternalType($type): self { |
|
28
|
|
|
$this->startStep('is not internal type "' . $type . '"') |
|
29
|
|
|
->assertNotInternalType($type); |
|
30
|
|
|
|
|
31
|
|
|
return $this; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @return $this |
|
36
|
|
|
*/ |
|
37
|
|
|
public function isEqualTo($expected, $expectedValueName = '') { |
|
38
|
|
|
$stepName = $expectedValueName ? "is equal to {$expectedValueName}" : "is equal to expected"; |
|
39
|
|
|
|
|
40
|
|
|
$this->startStep($stepName) |
|
41
|
|
|
->assertEquals($expected); |
|
42
|
|
|
|
|
43
|
|
|
return $this; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return $this |
|
48
|
|
|
*/ |
|
49
|
|
|
public function isNotEqualTo($expected, $expectedValueName = '') { |
|
50
|
|
|
$stepName = $expectedValueName ? "is not equal to {$expectedValueName}" : "is not equal to expected"; |
|
51
|
|
|
$this->startStep($stepName) |
|
52
|
|
|
->assertNotEquals($expected); |
|
53
|
|
|
|
|
54
|
|
|
return $this; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return $this |
|
59
|
|
|
*/ |
|
60
|
|
|
public function isGreaterThan($expected): self { |
|
61
|
|
|
$this->startStep('is greater than "' . $expected . '"') |
|
62
|
|
|
->assertGreaterThan($expected); |
|
63
|
|
|
|
|
64
|
|
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return $this |
|
69
|
|
|
*/ |
|
70
|
|
|
public function isLessThan($expected): self { |
|
71
|
|
|
$this->startStep('is less than "' . $expected . '"') |
|
72
|
|
|
->assertLessThan($expected); |
|
73
|
|
|
|
|
74
|
|
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return $this |
|
79
|
|
|
*/ |
|
80
|
|
|
public function isGreaterOrEqualTo($expected): self { |
|
81
|
|
|
$this->startStep('is greater or equal to "' . $expected . '"') |
|
82
|
|
|
->assertGreaterThanOrEqual($expected); |
|
83
|
|
|
|
|
84
|
|
|
return $this; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return $this |
|
89
|
|
|
*/ |
|
90
|
|
|
public function isLessOrEqualTo($expected): self { |
|
91
|
|
|
$this->startStep('is less or equal to "' . $expected . '"') |
|
92
|
|
|
->assertLessThanOrEqual($expected); |
|
93
|
|
|
|
|
94
|
|
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return $this |
|
99
|
|
|
*/ |
|
100
|
|
|
public function isNull(): self { |
|
101
|
|
|
$this->startStep('is null') |
|
102
|
|
|
->assertNull(); |
|
103
|
|
|
|
|
104
|
|
|
return $this; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @return $this |
|
109
|
|
|
*/ |
|
110
|
|
|
public function isNotNull(): self { |
|
111
|
|
|
$this->startStep('is not null') |
|
112
|
|
|
->assertNotNull(); |
|
113
|
|
|
|
|
114
|
|
|
return $this; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @return $this |
|
119
|
|
|
*/ |
|
120
|
|
|
public function isEmpty(): self { |
|
121
|
|
|
$this->startStep('is empty') |
|
122
|
|
|
->assertEmpty(); |
|
123
|
|
|
|
|
124
|
|
|
return $this; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return $this |
|
129
|
|
|
*/ |
|
130
|
|
|
public function isNotEmpty(): self { |
|
131
|
|
|
$this->startStep('is not empty') |
|
132
|
|
|
->assertNotEmpty(); |
|
133
|
|
|
|
|
134
|
|
|
return $this; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @return $this |
|
139
|
|
|
*/ |
|
140
|
|
|
public function isTheSameAs($expected, $expectedValueName = '') { |
|
141
|
|
|
$stepName = $expectedValueName ? "is the same as {$expectedValueName}" : "is the same as expected"; |
|
142
|
|
|
$this->startStep($stepName) |
|
143
|
|
|
->assertSame($expected); |
|
144
|
|
|
|
|
145
|
|
|
return $this; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @return $this |
|
150
|
|
|
*/ |
|
151
|
|
|
public function isNotTheSameAs($expected, $expectedValueName = '') { |
|
152
|
|
|
$stepName = $expectedValueName ? "is not the same as {$expectedValueName}" : "is not the same as expected"; |
|
153
|
|
|
|
|
154
|
|
|
$this->startStep($stepName) |
|
155
|
|
|
->assertNotSame($expected); |
|
156
|
|
|
|
|
157
|
|
|
return $this; |
|
158
|
|
|
} |
|
159
|
|
|
} |