Completed
Push — master ( 37982b...2b9d5b )
by Alex
04:24
created

testIsTFacetAttributeValidBadCollation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 13
loc 13
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace AlgoWeb\ODataMetadata\Tests\v3\edm;
4
5
use AlgoWeb\ODataMetadata\MetadataV3\edm\TValueTermType;
6
use AlgoWeb\ODataMetadata\Tests\TestCase;
7
use Mockery as m;
8
9
class TValueTermTypeTest extends TestCase
10
{
11
    public function testSetGetNullableRoundTrip()
12
    {
13
        $foo = new TValueTermType();
14
        $foo->setNullable(true);
15
        $this->assertTrue($foo->getNullable());
16
    }
17
18
    public function testSetGetNullableRoundTripNotBool()
19
    {
20
        $foo = new TValueTermType();
21
        $foo->setNullable('nullable');
1 ignored issue
show
Documentation introduced by
'nullable' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
22
        $this->assertTrue($foo->getNullable());
23
    }
24
25 View Code Duplication
    public function testSetBadMaxLength()
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...
26
    {
27
        $expected = 'Input must be numeric';
28
        $actual = null;
29
30
        $foo = new TValueTermType();
31
32
        try {
33
            $foo->setMaxLength(" _ ");
34
        } catch (\InvalidArgumentException $e) {
35
            $actual = $e->getMessage();
36
        }
37
        $this->assertEquals($expected, $actual);
38
    }
39
40 View Code Duplication
    public function testSetGetMaxLengthRoundTrip()
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...
41
    {
42
        $expected = "11";
43
        $actual = null;
1 ignored issue
show
Unused Code introduced by
$actual is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
44
45
        $foo = new TValueTermType();
46
        $foo->setMaxLength($expected);
47
        $actual = $foo->getMaxLength();
48
49
        $this->assertEquals($expected, $actual);
50
    }
51
52
    public function testSetNullMaxLength()
53
    {
54
        $foo = new TValueTermType();
55
        $foo->setMaxLength(null);
56
        $this->assertNull($foo->getMaxLength());
57
    }
58
59 View Code Duplication
    public function testSetBadFixedLength()
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
        $expected = 'Fixed length must be a valid TFixedLengthFacet';
62
        $actual = null;
63
64
        $foo = new TValueTermType();
65
66
        try {
67
            $foo->setFixedLength(" _ ");
1 ignored issue
show
Documentation introduced by
' _ ' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
68
        } catch (\InvalidArgumentException $e) {
69
            $actual = $e->getMessage();
70
        }
71
        $this->assertEquals($expected, $actual);
72
    }
73
74 View Code Duplication
    public function testSetGetFixedLengthRoundTrip()
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...
75
    {
76
        $expected = true;
77
        $actual = null;
1 ignored issue
show
Unused Code introduced by
$actual is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
78
79
        $foo = new TValueTermType();
80
        $foo->setFixedLength($expected);
81
        $actual = $foo->getFixedLength();
82
83
        $this->assertEquals($expected, $actual);
84
    }
85
86 View Code Duplication
    public function testSetBadPrecision()
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
        $expected = 'Input must be numeric';
89
        $actual = null;
90
91
        $foo = new TValueTermType();
92
93
        try {
94
            $foo->setPrecision(" _ ");
95
        } catch (\InvalidArgumentException $e) {
96
            $actual = $e->getMessage();
97
        }
98
        $this->assertEquals($expected, $actual);
99
    }
100
101 View Code Duplication
    public function testSetGetPrecisionRoundTrip()
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...
102
    {
103
        $expected = "11";
104
        $actual = null;
1 ignored issue
show
Unused Code introduced by
$actual is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
105
106
        $foo = new TValueTermType();
107
        $foo->setPrecision($expected);
108
        $actual = $foo->getPrecision();
109
110
        $this->assertEquals($expected, $actual);
111
    }
112
113
    public function testSetNullPrecision()
114
    {
115
        $foo = new TValueTermType();
116
        $foo->setPrecision(null);
117
        $this->assertNull($foo->getPrecision());
118
    }
119
120 View Code Duplication
    public function testSetBadScale()
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...
121
    {
122
        $expected = 'Input must be numeric';
123
        $actual = null;
124
125
        $foo = new TValueTermType();
126
127
        try {
128
            $foo->setScale(" _ ");
129
        } catch (\InvalidArgumentException $e) {
130
            $actual = $e->getMessage();
131
        }
132
        $this->assertEquals($expected, $actual);
133
    }
134
135 View Code Duplication
    public function testSetGetScaleRoundTrip()
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...
136
    {
137
        $expected = "11";
138
        $actual = null;
1 ignored issue
show
Unused Code introduced by
$actual is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
139
140
        $foo = new TValueTermType();
141
        $foo->setScale($expected);
142
        $actual = $foo->getScale();
143
144
        $this->assertEquals($expected, $actual);
145
    }
146
147
    public function testSetNullScale()
148
    {
149
        $foo = new TValueTermType();
150
        $foo->setScale(null);
151
        $this->assertNull($foo->getScale());
152
    }
153
154 View Code Duplication
    public function testSetBadUnicode()
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...
155
    {
156
        $expected = 'Unicode must be a valid TUnicodeFacet';
157
        $actual = null;
158
159
        $foo = new TValueTermType();
160
161
        try {
162
            $foo->setUnicode(" _ ");
1 ignored issue
show
Documentation introduced by
' _ ' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
163
        } catch (\InvalidArgumentException $e) {
164
            $actual = $e->getMessage();
165
        }
166
        $this->assertEquals($expected, $actual);
167
    }
168
169 View Code Duplication
    public function testSetGetUnicodeRoundTrip()
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...
170
    {
171
        $expected = true;
172
        $actual = null;
1 ignored issue
show
Unused Code introduced by
$actual is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
173
174
        $foo = new TValueTermType();
175
        $foo->setUnicode($expected);
176
        $actual = $foo->getUnicode();
177
178
        $this->assertEquals($expected, $actual);
179
    }
180
181
    public function testSetBadCollation()
182
    {
183
        $expected = "Collation must be a valid TCollationFacet";
184
        $actual = null;
185
186
        $foo = new TValueTermType();
187
188
        try {
189
            $foo->setCollation(new \DateTime());
1 ignored issue
show
Documentation introduced by
new \DateTime() is of type object<DateTime>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
190
        } catch (\InvalidArgumentException $e) {
191
            $actual = $e->getMessage();
192
        }
193
        $this->assertEquals($expected, $actual);
194
    }
195
196
    public function testSetGetCollationRoundTrip()
197
    {
198
        $expected = "swedish";
199
        $actual = null;
1 ignored issue
show
Unused Code introduced by
$actual is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
200
201
        $foo = new TValueTermType();
202
        $foo->setCollation($expected);
203
        $actual = $foo->getCollation();
204
205
        $this->assertEquals($expected, $actual);
206
    }
207
208 View Code Duplication
    public function testSetBadSRID()
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...
209
    {
210
        $expected = 'Input must be numeric';
211
        $actual = null;
212
213
        $foo = new TValueTermType();
214
215
        try {
216
            $foo->setSRID(" _ ");
217
        } catch (\InvalidArgumentException $e) {
218
            $actual = $e->getMessage();
219
        }
220
        $this->assertEquals($expected, $actual);
221
    }
222
223 View Code Duplication
    public function testSetGetSRIDRoundTrip()
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...
224
    {
225
        $expected = "11";
226
        $actual = null;
1 ignored issue
show
Unused Code introduced by
$actual is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
227
228
        $foo = new TValueTermType();
229
        $foo->setSRID($expected);
230
        $actual = $foo->getSRID();
231
232
        $this->assertEquals($expected, $actual);
233
    }
234
235 View Code Duplication
    public function testSetNullSRID()
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...
236
    {
237
        $expected = 'Input must be a string';
238
        $actual = null;
239
240
        $foo = new TValueTermType();
241
        try {
242
            $foo->setSRID(null);
243
        } catch (\InvalidArgumentException $e) {
244
            $actual = $e->getMessage();
245
        }
246
        $this->assertEquals($expected, $actual);
247
    }
248
249
    public function testIsTFacetAttributeValidNewCreation()
250
    {
251
        $expected = 'Nullable must be boolean: AlgoWeb\ODataMetadata\MetadataV3\edm\TValueTermType';
252
        $actual = null;
253
254
        $foo = new TValueTermType();
255
        $this->assertFalse($foo->isTFacetAttributesTraitValid($actual));
256
        $this->assertEquals($expected, $actual);
257
    }
258
259
    public function testIsTFacetAttributeValidNullableSet()
260
    {
261
        $expected = '';
262
        $actual = null;
263
264
        $foo = new TValueTermType();
265
        $foo->setNullable(true);
266
        $this->assertTrue($foo->isTFacetAttributesTraitValid($actual));
267
        $this->assertEquals($expected, $actual);
268
    }
269
270 View Code Duplication
    public function testIsTFacetAttributeValidBadCollation()
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...
271
    {
272
        $expected = "Collation must be a valid TCollationFacet:";
273
        $actual = null;
274
275
        $foo = m::mock(TValueTermType::class)->makePartial();
276
        $foo->setNullable(true);
277
        $foo->shouldReceive('isTCollationFacetValid')->andReturn(true, false)->twice();
278
279
        $foo->setCollation(' _ ');
280
        $this->assertFalse($foo->isTFacetAttributesTraitValid($actual));
281
        $this->assertStringStartsWith($expected, $actual);
282
    }
283
284 View Code Duplication
    public function testIsTFacetAttributeValidBadMaxLength()
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...
285
    {
286
        $expected = "Max length must be a valid TMaxLengthFacet: ";
287
        $actual = null;
288
289
        $foo = m::mock(TValueTermType::class)->makePartial();
290
        $foo->setNullable(true);
291
        $foo->shouldReceive('isTMaxLengthFacetValid')->andReturn(true, false)->twice();
292
293
        $foo->setMaxLength(' _ ');
294
        $this->assertFalse($foo->isTFacetAttributesTraitValid($actual));
295
        $this->assertStringStartsWith($expected, $actual);
296
    }
297
298 View Code Duplication
    public function testIsTFacetAttributeValidBadFixedLength()
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...
299
    {
300
        $expected = "Fixed length must be a valid TFixedLengthFacet: ";
301
        $actual = null;
302
303
        $foo = m::mock(TValueTermType::class)->makePartial();
304
        $foo->setNullable(true);
305
        $foo->shouldReceive('isTIsFixedLengthFacetTraitValid')->andReturn(true, false)->twice();
306
307
        $foo->setFixedLength(' _ ');
308
        $this->assertFalse($foo->isTFacetAttributesTraitValid($actual));
309
        $this->assertStringStartsWith($expected, $actual);
310
    }
311
312 View Code Duplication
    public function testIsTFacetAttributeValidBadPrecision()
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...
313
    {
314
        $expected = "Precision must be a valid TPrecisionFacet: ";
315
        $actual = null;
316
317
        $foo = m::mock(TValueTermType::class)->makePartial();
318
        $foo->setNullable(true);
319
        $foo->shouldReceive('isTPrecisionFacetValid')->andReturn(true, false)->twice();
320
321
        $foo->setPrecision(' _ ');
322
        $this->assertFalse($foo->isTFacetAttributesTraitValid($actual));
323
        $this->assertStringStartsWith($expected, $actual);
324
    }
325
326 View Code Duplication
    public function testIsTFacetAttributeValidBadScale()
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...
327
    {
328
        $expected = "Scale must be a valid TScaleFacet: ";
329
        $actual = null;
330
331
        $foo = m::mock(TValueTermType::class)->makePartial();
332
        $foo->setNullable(true);
333
        $foo->shouldReceive('isTScaleFacetValid')->andReturn(true, false)->twice();
334
335
        $foo->setScale(' _ ');
336
        $this->assertFalse($foo->isTFacetAttributesTraitValid($actual));
337
        $this->assertStringStartsWith($expected, $actual);
338
    }
339
340 View Code Duplication
    public function testIsTFacetAttributeValidBadSRID()
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...
341
    {
342
        $expected = "SRID must be a valid TSridFacet: ";
343
        $actual = null;
344
345
        $foo = m::mock(TValueTermType::class)->makePartial();
346
        $foo->setNullable(true);
347
        $foo->shouldReceive('isTSridFacetValid')->andReturn(true, false)->twice();
348
349
        $foo->setSRID(' _ ');
350
        $this->assertFalse($foo->isTFacetAttributesTraitValid($actual));
351
        $this->assertStringStartsWith($expected, $actual);
352
    }
353
354 View Code Duplication
    public function testIsTFacetAttributeValidBadUnicode()
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...
355
    {
356
        $expected = "Unicode must be a valid TUnicodeFacet: ";
357
        $actual = null;
358
359
        $foo = m::mock(TValueTermType::class)->makePartial();
360
        $foo->setNullable(true);
361
        $foo->shouldReceive('isTIsUnicodeFacetTraitValid')->andReturn(true, false)->twice();
362
363
        $foo->setUnicode(' _ ');
364
        $this->assertFalse($foo->isTFacetAttributesTraitValid($actual));
365
        $this->assertStringStartsWith($expected, $actual);
366
    }
367
}
368