1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\ODataMetadata\Tests; |
4
|
|
|
|
5
|
|
|
use phpDocumentor\Reflection\Types\This; |
6
|
|
|
use \Mockery as m; |
7
|
|
|
|
8
|
|
|
class TestTypeTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
public function testIsStringNotNullOrEmptyWithNull() |
11
|
|
|
{ |
12
|
|
|
$string = null; |
13
|
|
|
$foo = new TestType(); |
14
|
|
|
$this->assertFalse($foo->isStringNotNullOrEmpty($string)); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function testIsStringNotNullOrEmptyWithEmpty() |
18
|
|
|
{ |
19
|
|
|
$string = ''; |
20
|
|
|
$foo = new TestType(); |
21
|
|
|
$this->assertFalse($foo->isStringNotNullOrEmpty($string)); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testIsStringNotNullOrEmptyWithNonString() |
25
|
|
|
{ |
26
|
|
|
$string = new \stdClass(); |
27
|
|
|
$foo = new TestType(); |
28
|
|
|
$this->assertFalse($foo->isStringNotNullOrEmpty($string)); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testIsStringNotNullOrEmptyWithObject() |
32
|
|
|
{ |
33
|
|
|
$string = new \stdClass(); |
34
|
|
|
$foo = new TestType(); |
35
|
|
|
$this->assertFalse($foo->isStringNotNullOrEmpty($string)); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testIsStringNotNullOrEmptyWithNumber() |
39
|
|
|
{ |
40
|
|
|
$string = 2134; |
41
|
|
|
$foo = new TestType(); |
42
|
|
|
$this->assertFalse($foo->isStringNotNullOrEmpty($string)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testIsStringNotNullOrEmptyWithString() |
46
|
|
|
{ |
47
|
|
|
$string = 'An actual string'; |
48
|
|
|
$foo = new TestType(); |
49
|
|
|
$this->assertTrue($foo->isStringNotNullOrEmpty($string)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testIsStringNotNullOrEmptyWithNumberAsString() |
53
|
|
|
{ |
54
|
|
|
$string = '1234'; |
55
|
|
|
$foo = new TestType(); |
56
|
|
|
$this->assertTrue($foo->isStringNotNullOrEmpty($string)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testIsNotNullInstanceOfWhenPassedObjectToCheck() |
60
|
|
|
{ |
61
|
|
|
$var = new \stdClass(); |
62
|
|
|
$instanceof = new \stdClass(); |
63
|
|
|
|
64
|
|
|
$foo = new TestType(); |
65
|
|
|
$this->assertTrue($foo->isNotNullInstanceOf($var, $instanceof)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testIsNotNullInstanceOfWhenPassedStringToCheck() |
69
|
|
|
{ |
70
|
|
|
$var = new \stdClass(); |
71
|
|
|
$instanceof = get_class($var); |
72
|
|
|
|
73
|
|
|
$foo = new TestType(); |
74
|
|
|
$this->assertTrue($foo->isNotNullInstanceOf($var, $instanceof)); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testIsNotNullInstanceOfWhenPassedNonObjectToCheck() |
78
|
|
|
{ |
79
|
|
|
$var = 'Another string. How amazing.'; |
80
|
|
|
$instanceof = new \stdClass(); |
81
|
|
|
|
82
|
|
|
$foo = new TestType(); |
83
|
|
|
$this->assertFalse($foo->isNotNullInstanceOf($var, $instanceof)); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testIsNotNullInstanceOfWhenPassedNullToCheck() |
87
|
|
|
{ |
88
|
|
|
$var = null; |
89
|
|
|
$instanceof = new \stdClass(); |
90
|
|
|
|
91
|
|
|
$foo = new TestType(); |
92
|
|
|
$this->assertFalse($foo->isNotNullInstanceOf($var, $instanceof)); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testIsNullInstanceOfWhenPassedObjectToCheck() |
96
|
|
|
{ |
97
|
|
|
$var = new \stdClass(); |
98
|
|
|
$instanceof = new \stdClass(); |
99
|
|
|
|
100
|
|
|
$foo = new TestType(); |
101
|
|
|
$this->assertFalse($foo->isNullInstanceOf($var, $instanceof)); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
View Code Duplication |
public function testIsNullInstanceOfWhenPassedStringToCheck() |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
$var = new \stdClass(); |
107
|
|
|
$instanceof = get_class($var); |
108
|
|
|
|
109
|
|
|
$foo = new TestType(); |
110
|
|
|
$this->assertFalse($foo->isNullInstanceOf($var, $instanceof)); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function testIsNullInstanceOfWhenPassedNonObjectToCheck() |
114
|
|
|
{ |
115
|
|
|
$var = 'Another string. How amazing.'; |
116
|
|
|
$instanceof = new \stdClass(); |
117
|
|
|
|
118
|
|
|
$foo = new TestType(); |
119
|
|
|
$this->assertFalse($foo->isNullInstanceOf($var, $instanceof)); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function testIsNullInstanceOfWhenPassedNullToCheck() |
123
|
|
|
{ |
124
|
|
|
$var = null; |
125
|
|
|
$instanceof = new \stdClass(); |
126
|
|
|
|
127
|
|
|
$foo = new TestType(); |
128
|
|
|
$this->assertTrue($foo->isNullInstanceOf($var, $instanceof)); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
View Code Duplication |
public function testIsValidArrayNotEnoughBitz() |
|
|
|
|
132
|
|
|
{ |
133
|
|
|
$arr = []; |
134
|
|
|
$instanceof = get_class(new \stdClass()); |
135
|
|
|
|
136
|
|
|
$foo = new TestType(); |
137
|
|
|
$this->assertFalse($foo->isValidArray($arr, $instanceof, 1, -1)); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
View Code Duplication |
public function testIsValidArrayTooManyBitz() |
|
|
|
|
141
|
|
|
{ |
142
|
|
|
$arr = ['abc']; |
143
|
|
|
$instanceof = get_class(new \stdClass()); |
144
|
|
|
|
145
|
|
|
$foo = new TestType(); |
146
|
|
|
$this->assertFalse($foo->isValidArray($arr, $instanceof, 0, 0)); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
View Code Duplication |
public function testIsValidArrayWrongType() |
|
|
|
|
150
|
|
|
{ |
151
|
|
|
$arr = ['abc']; |
152
|
|
|
$instanceof = get_class(new \stdClass()); |
153
|
|
|
|
154
|
|
|
$foo = new TestType(); |
155
|
|
|
$this->assertFalse($foo->isValidArray($arr, $instanceof)); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
View Code Duplication |
public function testIsValidArrayRightType() |
|
|
|
|
159
|
|
|
{ |
160
|
|
|
$arr = [new \stdClass()]; |
161
|
|
|
$instanceof = get_class(new \stdClass()); |
162
|
|
|
|
163
|
|
|
$foo = new TestType(); |
164
|
|
|
$this->assertTrue($foo->isValidArray($arr, $instanceof)); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function testIsChildArrayOkForEmptyArray() |
168
|
|
|
{ |
169
|
|
|
$msg = null; |
170
|
|
|
$arr = []; |
171
|
|
|
|
172
|
|
|
$foo = new TestType(); |
173
|
|
|
$this->assertTrue($foo->isChildArrayOK($arr, $msg), $msg); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function testIsChildArrayOkForNonEmptyArrayWithBadGubbins() |
177
|
|
|
{ |
178
|
|
|
$msg = null; |
179
|
|
|
$expected = "Child item is not an instance of IsOK"; |
180
|
|
|
$arr = ['abc']; |
181
|
|
|
|
182
|
|
|
$foo = new TestType(); |
183
|
|
|
$this->assertFalse($foo->isChildArrayOK($arr, $msg), $msg); |
184
|
|
|
$this->assertEquals($expected, $msg); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function testIsChildArrayOkForNonEmptyArrayWithGoodGubbinsNotOk() |
188
|
|
|
{ |
189
|
|
|
$bar = m::mock(TestType::class); |
190
|
|
|
// closure needs to return true to match the matcher and thus trip the andReturn(false) bit |
191
|
|
|
$bar->shouldReceive('isOK')->with(m::on(function (&$msg) { |
192
|
|
|
$msg = 'OH NOES!'; |
193
|
|
|
return true; |
194
|
|
|
}))->andReturn(false); |
195
|
|
|
|
196
|
|
|
$msg = null; |
197
|
|
|
$expected = "OH NOES!"; |
198
|
|
|
$arr = [ $bar ]; |
199
|
|
|
|
200
|
|
|
$foo = new TestType(); |
201
|
|
|
$this->assertFalse($foo->isChildArrayOK($arr, $msg), $msg); |
202
|
|
|
$this->assertEquals($expected, $msg); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
public function testIsUrlValidWithNull() |
206
|
|
|
{ |
207
|
|
|
$url = null; |
208
|
|
|
|
209
|
|
|
$foo = new TestType(); |
210
|
|
|
$this->assertFalse($foo->isURLValid($url)); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function testIsUrlValidWithNonUrlString() |
214
|
|
|
{ |
215
|
|
|
$url = 'abc'; |
216
|
|
|
|
217
|
|
|
$foo = new TestType(); |
218
|
|
|
$this->assertFalse($foo->isURLValid($url)); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
public function testIsUrlValidWithUrlString() |
222
|
|
|
{ |
223
|
|
|
$url = 'https://google.com'; |
224
|
|
|
|
225
|
|
|
$foo = new TestType(); |
226
|
|
|
$this->assertTrue($foo->isURLValid($url)); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
public function testIsUrlValidWithUrlStringWithWWW() |
230
|
|
|
{ |
231
|
|
|
$url = 'http://www.google.com'; |
232
|
|
|
|
233
|
|
|
$foo = new TestType(); |
234
|
|
|
$this->assertTrue($foo->isURLValid($url)); |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
|
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.