Passed
Push — master ( bd41da...ca4ea4 )
by Alex
03:46
created

testObjectNullOrOkWithIsOkObjectNotOk()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
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 View Code Duplication
    public function testIsNotNullInstanceOfWhenPassedObjectToCheck()
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...
60
    {
61
        $var = new \stdClass();
62
        $instanceof = new \stdClass();
63
64
        $foo = new testType();
65
        $this->assertTrue($foo->isNotNullInstanceOf($var, $instanceof));
66
    }
67
68 View Code Duplication
    public function testIsNotNullInstanceOfWhenPassedStringToCheck()
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...
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 View Code Duplication
    public function testIsNotNullInstanceOfWhenPassedNonObjectToCheck()
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...
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 View Code Duplication
    public function testIsNotNullInstanceOfWhenPassedNullToCheck()
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...
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()
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...
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 View Code Duplication
    public function testIsNullInstanceOfWhenPassedNullToCheck()
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...
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()
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...
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()
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...
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()
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...
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()
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...
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
    public function testObjectNullOrOkWithNullObject()
238
    {
239
        $msg = null;
240
        $obj = null;
241
        $foo = new testType();
242
        $this->assertTrue($foo->isObjectNullOrOk($obj, $msg));
243
    }
244
245
    public function testObjectNullOrOkWithIsOkObjectActuallyOk()
246
    {
247
        $msg = null;
248
        $obj = m::mock(testType::class);
249
        // closure needs to return true to match the matcher and thus trip the andReturn(false) bit
250
        $obj->shouldReceive('isOK')->with(m::on(function (&$msg) {
251
            $msg = null;
252
            return true;
253
        }))->andReturn(true);
254
        $foo = new testType();
255
        $this->assertTrue($foo->isObjectNullOrOk($obj, $msg));
256
    }
257
258
    public function testObjectNullOrOkWithIsOkObjectNotOk()
259
    {
260
        $msg = null;
261
        $obj = m::mock(testType::class);
262
        // closure needs to return true to match the matcher and thus trip the andReturn(false) bit
263
        $obj->shouldReceive('isOK')->with(m::on(function (&$msg) {
264
            $msg = 'OH NOES!';
265
            return true;
266
        }))->andReturn(false);
267
        $expected = 'OH NOES!';
268
        $foo = new testType();
269
        $this->assertFalse($foo->isObjectNullOrOk($obj, $msg));
270
        $this->assertEquals($expected, $msg);
271
    }
272
273
    public function testIsValidArrayOkWhenNotValidArray()
274
    {
275
        $foo = m::mock(testType::class)->makePartial();
276
        $foo->shouldReceive('isValidArray')->withAnyArgs()->andReturn(false);
277
278
        $expected = "Supplied array not a valid array";
279
        $msg = null;
280
        $this->assertFalse($foo->isValidArrayOk([], '', $msg));
281
        $this->assertEquals($expected, $msg);
282
    }
283
284
    public function testIsValidArrayOkWhenChildArrayNotOK()
285
    {
286
        $foo = m::mock(testType::class)->makePartial();
287
        $foo->shouldReceive('isValidArray')->withAnyArgs()->andReturn(true);
288
        $foo->shouldReceive('isChildArrayOK')->with(m::any(), m::on(function (&$msg) {
289
            $msg = 'OH NOES!';
290
            return true;
291
        }))->andReturn(false);
292
        $expected = 'OH NOES!';
293
        $msg = null;
294
        $this->assertFalse($foo->isValidArrayOK([], '', $msg));
295
        $this->assertEquals($expected, $msg);
296
    }
297
298
    public function testIsValidArrayOkWhenChildArrayIsOk()
299
    {
300
        $foo = m::mock(testType::class)->makePartial();
301
        $foo->shouldReceive('isValidArray')->withAnyArgs()->andReturn(true);
302
        $foo->shouldReceive('isChildArrayOK')->with(m::any(), m::on(function (&$msg) {
303
            $msg = null;
304
            return true;
305
        }))->andReturn(true);
306
        $expected = null;
307
        $msg = null;
308
        $this->assertTrue($foo->isValidArrayOK([], '', $msg));
309
        $this->assertEquals($expected, $msg);
310
    }
311
}
312