Completed
Push — master ( 819155...51529b )
by Alex
04:17
created

testSimpleIdentifierValidWithoutTrailingSpace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace AlgoWeb\ODataMetadata\Tests;
4
5
use \Mockery as m;
6
7
class TestTypeTest extends TestCase
8
{
9
    public function testIsStringNotNullOrEmptyWithNull()
10
    {
11
        $string = null;
12
        $foo = new testType();
13
        $this->assertFalse($foo->isStringNotNullOrEmpty($string));
14
    }
15
16
    public function testIsStringNotNullOrEmptyWithEmpty()
17
    {
18
        $string = '';
19
        $foo = new testType();
20
        $this->assertFalse($foo->isStringNotNullOrEmpty($string));
21
    }
22
23
    public function testIsStringNotNullOrEmptyWithNonString()
24
    {
25
        $string = new \stdClass();
26
        $foo = new testType();
27
        $this->assertFalse($foo->isStringNotNullOrEmpty($string));
28
    }
29
30
    public function testIsStringNotNullOrEmptyWithObject()
31
    {
32
        $string = new \stdClass();
33
        $foo = new testType();
34
        $this->assertFalse($foo->isStringNotNullOrEmpty($string));
35
    }
36
37
    public function testIsStringNotNullOrEmptyWithNumber()
38
    {
39
        $string = 2134;
40
        $foo = new testType();
41
        $this->assertFalse($foo->isStringNotNullOrEmpty($string));
42
    }
43
44
    public function testIsStringNotNullOrEmptyWithString()
45
    {
46
        $string = 'An actual string';
47
        $foo = new testType();
48
        $this->assertTrue($foo->isStringNotNullOrEmpty($string));
49
    }
50
51
    public function testIsStringNotNullOrEmptyWithNumberAsString()
52
    {
53
        $string = '1234';
54
        $foo = new testType();
55
        $this->assertTrue($foo->isStringNotNullOrEmpty($string));
56
    }
57
58 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...
59
    {
60
        $var = new \stdClass();
61
        $instanceof = new \stdClass();
62
63
        $foo = new testType();
64
        $this->assertTrue($foo->isNotNullInstanceOf($var, $instanceof));
65
    }
66
67 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...
68
    {
69
        $var = new \stdClass();
70
        $instanceof = get_class($var);
71
72
        $foo = new testType();
73
        $this->assertTrue($foo->isNotNullInstanceOf($var, $instanceof));
74
    }
75
76 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...
77
    {
78
        $var = 'Another string.  How amazing.';
79
        $instanceof = new \stdClass();
80
81
        $foo = new testType();
82
        $this->assertFalse($foo->isNotNullInstanceOf($var, $instanceof));
83
    }
84
85 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...
86
    {
87
        $var = null;
88
        $instanceof = new \stdClass();
89
90
        $foo = new testType();
91
        $this->assertFalse($foo->isNotNullInstanceOf($var, $instanceof));
92
    }
93
94
    public function testIsNullInstanceOfWhenPassedObjectToCheck()
95
    {
96
        $var = new \stdClass();
97
        $instanceof = new \stdClass();
98
99
        $foo = new testType();
100
        $this->assertFalse($foo->isNullInstanceOf($var, $instanceof));
101
    }
102
103 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...
104
    {
105
        $var = new \stdClass();
106
        $instanceof = get_class($var);
107
108
        $foo = new testType();
109
        $this->assertFalse($foo->isNullInstanceOf($var, $instanceof));
110
    }
111
112
    public function testIsNullInstanceOfWhenPassedNonObjectToCheck()
113
    {
114
        $var = 'Another string.  How amazing.';
115
        $instanceof = new \stdClass();
116
117
        $foo = new testType();
118
        $this->assertFalse($foo->isNullInstanceOf($var, $instanceof));
119
    }
120
121 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...
122
    {
123
        $var = null;
124
        $instanceof = new \stdClass();
125
126
        $foo = new testType();
127
        $this->assertTrue($foo->isNullInstanceOf($var, $instanceof));
128
    }
129
130 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...
131
    {
132
        $arr = [];
133
        $instanceof = get_class(new \stdClass());
134
135
        $foo = new testType();
136
        $this->assertFalse($foo->isValidArray($arr, $instanceof, 1, -1));
137
    }
138
139 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...
140
    {
141
        $arr = ['abc'];
142
        $instanceof = get_class(new \stdClass());
143
144
        $foo = new testType();
145
        $this->assertFalse($foo->isValidArray($arr, $instanceof, 0, 0));
146
    }
147
148 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...
149
    {
150
        $arr = ['abc'];
151
        $instanceof = get_class(new \stdClass());
152
153
        $foo = new testType();
154
        $this->assertFalse($foo->isValidArray($arr, $instanceof));
155
    }
156
157 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...
158
    {
159
        $arr = [new \stdClass()];
160
        $instanceof = get_class(new \stdClass());
161
162
        $foo = new testType();
163
        $this->assertTrue($foo->isValidArray($arr, $instanceof));
164
    }
165
166
    public function testIsChildArrayOkForEmptyArray()
167
    {
168
        $msg = null;
169
        $arr = [];
170
171
        $foo = new testType();
172
        $this->assertTrue($foo->isChildArrayOK($arr, $msg), $msg);
173
    }
174
175
    public function testIsChildArrayOkForNonEmptyArrayWithBadGubbins()
176
    {
177
        $msg = null;
178
        $expected = "Child item is not an instance of IsOK: AlgoWeb\\ODataMetadata\\Tests\\testType";
179
        $arr = ['abc'];
180
181
        $foo = new testType();
182
        $this->assertFalse($foo->isChildArrayOK($arr, $msg), $msg);
183
        $this->assertEquals($expected, $msg);
184
    }
185
186
    public function testIsChildArrayOkForNonEmptyArrayWithGoodGubbinsNotOk()
187
    {
188
        $bar = m::mock(testType::class);
189
        // closure needs to return true to match the matcher and thus trip the andReturn(false) bit
190
        $bar->shouldReceive('isOK')->with(m::on(function (&$msg) {
191
            $msg = 'OH NOES!';
192
            return true;
193
        }))->andReturn(false);
194
195
        $msg = null;
196
        $expected = "OH NOES!";
197
        $arr = [ $bar ];
198
199
        $foo = new testType();
200
        $this->assertFalse($foo->isChildArrayOK($arr, $msg), $msg);
201
        $this->assertEquals($expected, $msg);
202
    }
203
204
    public function testIsUrlValidWithNull()
205
    {
206
        $url = null;
207
208
        $foo = new testType();
209
        $this->assertFalse($foo->isURLValid($url));
210
    }
211
212
    public function testIsUrlValidWithNonUrlString()
213
    {
214
        $url = 'abc';
215
216
        $foo = new testType();
217
        $this->assertFalse($foo->isURLValid($url));
218
    }
219
220
    public function testIsUrlValidWithUrlString()
221
    {
222
        $url = 'https://google.com';
223
224
        $foo = new testType();
225
        $this->assertTrue($foo->isURLValid($url));
226
    }
227
228
    public function testIsUrlValidWithUrlStringWithWWW()
229
    {
230
        $url = 'http://www.google.com';
231
232
        $foo = new testType();
233
        $this->assertTrue($foo->isURLValid($url));
234
    }
235
236
    public function testObjectNullOrOkWithNullObject()
237
    {
238
        $msg = null;
239
        $obj = null;
240
        $foo = new testType();
241
        $this->assertTrue($foo->isObjectNullOrOk($obj, $msg));
242
    }
243
244
    public function testObjectNullOrOkWithIsOkObjectActuallyOk()
245
    {
246
        $msg = null;
247
        $obj = m::mock(testType::class);
248
        // closure needs to return true to match the matcher and thus trip the andReturn(false) bit
249
        $obj->shouldReceive('isOK')->with(m::on(function (&$msg) {
250
            $msg = null;
251
            return true;
252
        }))->andReturn(true);
253
        $foo = new testType();
254
        $this->assertTrue($foo->isObjectNullOrOk($obj, $msg));
255
    }
256
257
    public function testObjectNullOrOkWithIsOkObjectNotOk()
258
    {
259
        $msg = null;
260
        $obj = m::mock(testType::class);
261
        // closure needs to return true to match the matcher and thus trip the andReturn(false) bit
262
        $obj->shouldReceive('isOK')->with(m::on(function (&$msg) {
263
            $msg = 'OH NOES!';
264
            return true;
265
        }))->andReturn(false);
266
        $expected = 'OH NOES!';
267
        $foo = new testType();
268
        $this->assertFalse($foo->isObjectNullOrOk($obj, $msg));
269
        $this->assertEquals($expected, $msg);
270
    }
271
272
    public function testIsValidArrayOkWhenNotValidArray()
273
    {
274
        $foo = m::mock(testType::class)->makePartial();
275
        $foo->shouldReceive('isValidArray')->withAnyArgs()->andReturn(false);
276
277
        $expected = "Supplied array not a valid array: Mockery_0_AlgoWeb_ODataMetadata_Tests_testType";
278
        $msg = null;
279
        $this->assertFalse($foo->isValidArrayOk([], '', $msg));
280
        $this->assertEquals($expected, $msg);
281
    }
282
283
    public function testIsValidArrayOkWhenChildArrayNotOK()
284
    {
285
        $foo = m::mock(testType::class)->makePartial();
286
        $foo->shouldReceive('isValidArray')->withAnyArgs()->andReturn(true);
287
        $foo->shouldReceive('isChildArrayOK')->with(m::any(), m::on(function (&$msg) {
288
            $msg = 'OH NOES!';
289
            return true;
290
        }))->andReturn(false);
291
        $expected = 'OH NOES!';
292
        $msg = null;
293
        $this->assertFalse($foo->isValidArrayOK([], '', $msg));
294
        $this->assertEquals($expected, $msg);
295
    }
296
297
    public function testIsValidArrayOkWhenChildArrayIsOk()
298
    {
299
        $foo = m::mock(testType::class)->makePartial();
300
        $foo->shouldReceive('isValidArray')->withAnyArgs()->andReturn(true);
301
        $foo->shouldReceive('isChildArrayOK')->with(m::any(), m::on(function (&$msg) {
302
            $msg = null;
303
            return true;
304
        }))->andReturn(true);
305
        $expected = null;
306
        $msg = null;
307
        $this->assertTrue($foo->isValidArrayOK([], '', $msg));
308
        $this->assertEquals($expected, $msg);
309
    }
310
311 View Code Duplication
    public function testReplaceStringStartingWithSpaces()
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...
312
    {
313
        $string = "This is a string";
314
        $expected = "This is a string";
315
        $foo = new testType();
316
        $result = $foo->replaceString($string);
317
        $this->assertEquals($expected, $result);
318
    }
319
320 View Code Duplication
    public function testReplaceStringStartingWithTabs()
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...
321
    {
322
        $string = "This\tis\ta\tstring";
323
        $expected = "This is a string";
324
        $foo = new testType();
325
        $result = $foo->replaceString($string);
326
        $this->assertEquals($expected, $result);
327
    }
328
329 View Code Duplication
    public function testReplaceStringStartingWithNuLines()
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...
330
    {
331
        $string = "This\nis\na\nstring";
332
        $expected = "This is a string";
333
        $foo = new testType();
334
        $result = $foo->replaceString($string);
335
        $this->assertEquals($expected, $result);
336
    }
337
338 View Code Duplication
    public function testReplaceStringWithPadding()
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...
339
    {
340
        $string = " This is a string ";
341
        $expected = " This is a string ";
342
        $foo = new testType();
343
        $result = $foo->replaceString($string);
344
        $this->assertEquals($expected, $result);
345
    }
346
347 View Code Duplication
    public function testCollapseStringWithSpacesAndPadding()
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...
348
    {
349
        $string = "  This  is  a  string  ";
350
        $expected = "This is a string";
351
        $foo = new testType();
352
        $result = $foo->collapseString($string);
353
        $this->assertEquals($expected, $result);
354
    }
355
356
    public function testSimpleIdentifierValidWithTrailingSpace()
357
    {
358
        $string = "UnitPrice ";
359
360
        $foo = new testType();
361
        $this->assertFalse($foo->isTSimpleIdentifierValid($string));
362
    }
363
364
    public function testSimpleIdentifierValidWithoutTrailingSpace()
365
    {
366
        $string = "UnitPrice";
367
368
        $foo = new testType();
369
        $this->assertTrue($foo->isTSimpleIdentifierValid($string));
370
    }
371
372
    public function testRegexPatternMatchAllOfString()
373
    {
374
        $string = "This! IS! UNITPRICE";
375
376
        $foo = new testType();
377
        $this->assertFalse($foo->isTSimpleIdentifierValid($string));
378
    }
379
}
380