Completed
Push — master ( 1aa683...bbb17c )
by Marc
01:37
created

testSetBinaryBitsetLeOutOrRangeBitsOfLastValidByte()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace MabeEnumTest;
4
5
use InvalidArgumentException;
6
use MabeEnum\EnumSet;
7
use MabeEnumTest\TestAsset\EmptyEnum;
8
use MabeEnumTest\TestAsset\EnumBasic;
9
use MabeEnumTest\TestAsset\EnumInheritance;
10
use MabeEnumTest\TestAsset\Enum32;
11
use MabeEnumTest\TestAsset\Enum64;
12
use MabeEnumTest\TestAsset\Enum65;
13
use MabeEnumTest\TestAsset\Enum66;
14
use PHPUnit_Framework_TestCase as TestCase;
15
16
/**
17
 * Unit tests for the class MabeEnum\EnumSet
18
 *
19
 * @link http://github.com/marc-mabe/php-enum for the canonical source repository
20
 * @copyright Copyright (c) 2015 Marc Bennewitz
21
 * @license http://github.com/marc-mabe/php-enum/blob/master/LICENSE.txt New BSD License
22
 */
23
class EnumSetTest extends TestCase
24
{
25
    public function testBasic()
26
    {
27
        $enumSet = new EnumSet(EnumBasic::class);
28
        $this->assertSame(EnumBasic::class, $enumSet->getEnumeration());
29
30
        $enum1  = EnumBasic::ONE();
31
        $enum2  = EnumBasic::TWO();
32
33
        $this->assertFalse($enumSet->contains($enum1));
34
        $this->assertNull($enumSet->attach($enum1));
35
        $this->assertTrue($enumSet->contains($enum1));
36
37
        $this->assertFalse($enumSet->contains($enum2));
38
        $this->assertNull($enumSet->attach($enum2));
39
        $this->assertTrue($enumSet->contains($enum2));
40
41
        $this->assertNull($enumSet->detach($enum1));
42
        $this->assertFalse($enumSet->contains($enum1));
43
44
        $this->assertNull($enumSet->detach($enum2));
45
        $this->assertFalse($enumSet->contains($enum2));
46
    }
47
48
    public function testBasicWithConstantValuesAsEnums()
49
    {
50
        $enumSet = new EnumSet(EnumBasic::class);
51
52
        $enum1  = EnumBasic::ONE;
53
        $enum2  = EnumBasic::TWO;
54
55
        $this->assertFalse($enumSet->contains($enum1));
56
        $this->assertNull($enumSet->attach($enum1));
57
        $this->assertTrue($enumSet->contains($enum1));
58
59
        $this->assertFalse($enumSet->contains($enum2));
60
        $this->assertNull($enumSet->attach($enum2));
61
        $this->assertTrue($enumSet->contains($enum2));
62
63
        $this->assertNull($enumSet->detach($enum1));
64
        $this->assertFalse($enumSet->contains($enum1));
65
66
        $this->assertNull($enumSet->detach($enum2));
67
        $this->assertFalse($enumSet->contains($enum2));
68
    }
69
70
    public function testUnique()
71
    {
72
        $enumSet = new EnumSet(EnumBasic::class);
73
74
        $enumSet->attach(EnumBasic::ONE());
75
        $enumSet->attach(EnumBasic::ONE);
76
77
        $enumSet->attach(EnumBasic::TWO());
78
        $enumSet->attach(EnumBasic::TWO);
79
80
        $this->assertSame(2, $enumSet->count());
81
    }
82
83
    public function testIterateOrdered()
84
    {
85
        $enumSet = new EnumSet(EnumBasic::class);
86
87
        // an empty enum set needs to be invalid, starting by 0
88
        $this->assertSame(0, $enumSet->count());
89
        $this->assertFalse($enumSet->valid());
90
        $this->assertNull($enumSet->current());
91
92
        // attach
93
        $enum1 = EnumBasic::ONE();
94
        $enum2 = EnumBasic::TWO();
95
        $enumSet->attach($enum1);
96
        $enumSet->attach($enum2);
97
98
        // a not empty enum set should be valid, starting by 0 (if not iterated)
99
        $enumSet->rewind();
100
        $this->assertSame(2, $enumSet->count());
101
        $this->assertTrue($enumSet->valid());
102
        $this->assertSame($enum1->getOrdinal(), $enumSet->key());
103
        $this->assertSame($enum1, $enumSet->current());
104
105
        // go to the next element (last)
106
        $this->assertNull($enumSet->next());
107
        $this->assertTrue($enumSet->valid());
108
        $this->assertSame($enum2->getOrdinal(), $enumSet->key());
109
        $this->assertSame($enum2, $enumSet->current());
110
111
        // go to the next element (out of range)
112
        $this->assertNull($enumSet->next());
113
        $this->assertFalse($enumSet->valid());
114
        $this->assertNull($enumSet->current());
115
116
        // rewind will set the iterator position back to 0
117
        $enumSet->rewind();
118
        $this->assertTrue($enumSet->valid());
119
        $this->assertSame(0, $enumSet->key());
120
        $this->assertSame($enum1, $enumSet->current());
121
    }
122
123
    public function testIterateAndDetach()
124
    {
125
        $enumSet = new EnumSet(EnumInheritance::class);
126
127
        $enum1 = EnumInheritance::ONE();
128
        $enum2 = EnumInheritance::TWO();
129
        $enum3 = EnumInheritance::INHERITANCE();
130
131
        // attach
132
        $enumSet->attach($enum1);
133
        $enumSet->attach($enum2);
134
        $enumSet->attach($enum3);
135
136
        // go to the next entry
137
        $enumSet->next();
138
        $this->assertSame($enum2, $enumSet->current());
139
140
        // detach current entry
141
        $enumSet->detach($enumSet->current());
142
        $this->assertFalse($enumSet->valid());
143
        $this->assertNull($enumSet->current());
144
        $this->assertSame($enum2->getOrdinal(), $enumSet->key());
145
146
        // go to the next entry should be the last entry
147
        $enumSet->next();
148
        $this->assertSame($enum3, $enumSet->current());
149
150
        // detech the last entry
151
        $enumSet->detach($enumSet->current());
152
        $this->assertFalse($enumSet->valid());
153
        $this->assertNull($enumSet->current());
154
        $this->assertSame($enum3->getOrdinal(), $enumSet->key());
155
    }
156
157
    public function testConstructThrowsInvalidArgumentExceptionIfEnumClassDoesNotExtendBaseEnum()
158
    {
159
        $this->setExpectedException(InvalidArgumentException::class);
160
        new EnumSet(self::class);
161
    }
162
163
    public function testInitEnumThrowsInvalidArgumentExceptionOnInvalidEnum()
164
    {
165
        $enumSet = new EnumSet(EnumBasic::class);
166
        $this->setExpectedException(InvalidArgumentException::class);
167
        $this->assertFalse($enumSet->contains(EnumInheritance::INHERITANCE()));
168
    }
169
170
    public function testIterateOutOfRangeIfLastOrdinalEnumIsSet()
171
    {
172
        $enumSet = new EnumSet(EnumBasic::class);
173
        $enum    = EnumBasic::byOrdinal(count(EnumBasic::getConstants()) - 1);
174
175
        $enumSet->attach($enum);
176
        $enumSet->rewind();
177
        $this->assertSame($enum, $enumSet->current());
178
179
        // go to the next entry results in out of range
180
        $enumSet->next();
181
        $this->assertFalse($enumSet->valid());
182
        $this->assertSame($enum->getOrdinal() + 1, $enumSet->key());
183
184
        // go more over doesn't change iterator position
185
        $enumSet->next();
186
        $this->assertFalse($enumSet->valid());
187
        $this->assertSame($enum->getOrdinal() + 1, $enumSet->key());
188
    }
189
190 View Code Duplication
    public function testRewindFirstOnEmptySet()
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...
191
    {
192
        $enumSet = new EnumSet(EnumBasic::class);
193
194
        $enumSet->attach(EnumBasic::TWO);
195
        $enumSet->rewind();
196
        $this->assertGreaterThan(0, $enumSet->key());
197
198
        $enumSet->detach(EnumBasic::TWO);
199
        $enumSet->rewind();
200
        $this->assertSame(0, $enumSet->key());
201
    }
202
203 View Code Duplication
    public function test32EnumerationsSet()
204
    {
205
        $enumSet = new EnumSet(Enum32::class);
206
        foreach (Enum32::getConstants() as $name => $value) {
207
            $this->assertFalse($enumSet->contains($value));
208
            $enumSet->attach($value);
209
            $this->assertTrue($enumSet->contains($value));
210
        }
211
212
        $this->assertSame(32, $enumSet->count());
213
214
        $expectedOrdinal = 0;
215
        foreach ($enumSet as $ordinal => $enum) {
216
            $this->assertSame($expectedOrdinal, $ordinal);
217
            $this->assertSame($expectedOrdinal, $enum->getOrdinal());
218
            $expectedOrdinal++;
219
        }
220
    }
221
222 View Code Duplication
    public function test64EnumerationsSet()
223
    {
224
        $enumSet = new EnumSet(Enum64::class);
225
        foreach (Enum64::getConstants() as $name => $value) {
226
            $this->assertFalse($enumSet->contains($value));
227
            $enumSet->attach($value);
228
            $this->assertTrue($enumSet->contains($value));
229
        }
230
231
        $this->assertSame(64, $enumSet->count());
232
233
        $expectedOrdinal = 0;
234
        foreach ($enumSet as $ordinal => $enum) {
235
            $this->assertSame($expectedOrdinal, $ordinal);
236
            $this->assertSame($expectedOrdinal, $enum->getOrdinal());
237
            $expectedOrdinal++;
238
        }
239
    }
240
241
    public function test65EnumerationsSet()
242
    {
243
        $enum = new EnumSet(Enum65::class);
244
245
        $this->assertNull($enum->attach(Enum65::byOrdinal(64)));
246
        $enum->next();
247
        $this->assertTrue($enum->valid());
248
    }
249
250 View Code Duplication
    public function testGetBinaryBitsetLe()
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...
251
    {
252
        $enumSet = new EnumSet(Enum65::class);
253
        
254
        $enum1 = Enum65::ONE;
255
        $enum2 = Enum65::TWO;
256
        $enum3 = Enum65::SIXTYFIVE;
257
        $enum4 = Enum65::SIXTYFOUR;
258
259
        $this->assertNull($enumSet->attach($enum1));
260
        $this->assertSame("\x01\x00\x00\x00\x00\x00\x00\x00\x00", $enumSet->getBinaryBitsetLe());
261
        $this->assertTrue($enumSet->contains($enum1));
262
263
        $this->assertNull($enumSet->attach($enum2));
264
        $this->assertSame("\x03\x00\x00\x00\x00\x00\x00\x00\x00", $enumSet->getBinaryBitsetLe());
265
        $this->assertTrue($enumSet->contains($enum2));
266
267
        $this->assertNull($enumSet->attach($enum3));
268
        $this->assertSame("\x03\x00\x00\x00\x00\x00\x00\x00\x01", $enumSet->getBinaryBitsetLe());
269
        $this->assertTrue($enumSet->contains($enum3));
270
271
        $this->assertNull($enumSet->attach($enum4));
272
        $this->assertSame("\x03\x00\x00\x00\x00\x00\x00\x80\x01", $enumSet->getBinaryBitsetLe());
273
        $this->assertTrue($enumSet->contains($enum4));
274
        
275
        $this->assertSame(4, $enumSet->count());
276
277
        $this->assertNull($enumSet->detach($enum2));
278
        $this->assertSame("\x01\x00\x00\x00\x00\x00\x00\x80\x01", $enumSet->getBinaryBitsetLe());
279
        $this->assertFalse($enumSet->contains($enum2));
280
        
281
        $this->assertSame(3, $enumSet->count());
282
    }
283
284 View Code Duplication
    public function testGetBinaryBitsetBe()
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
        $enumSet = new EnumSet(Enum65::class);
287
        
288
        $enum1 = Enum65::ONE;
289
        $enum2 = Enum65::TWO;
290
        $enum3 = Enum65::SIXTYFIVE;
291
        $enum4 = Enum65::SIXTYFOUR;
292
293
        $this->assertNull($enumSet->attach($enum1));
294
        $this->assertSame("\x00\x00\x00\x00\x00\x00\x00\x00\x01", $enumSet->getBinaryBitsetBe());
295
        $this->assertTrue($enumSet->contains($enum1));
296
297
        $this->assertNull($enumSet->attach($enum2));
298
        $this->assertSame("\x00\x00\x00\x00\x00\x00\x00\x00\x03", $enumSet->getBinaryBitsetBe());
299
        $this->assertTrue($enumSet->contains($enum2));
300
301
        $this->assertNull($enumSet->attach($enum3));
302
        $this->assertSame("\x01\x00\x00\x00\x00\x00\x00\x00\x03", $enumSet->getBinaryBitsetBe());
303
        $this->assertTrue($enumSet->contains($enum3));
304
305
        $this->assertNull($enumSet->attach($enum4));
306
        $this->assertSame("\x01\x80\x00\x00\x00\x00\x00\x00\x03", $enumSet->getBinaryBitsetBe());
307
        $this->assertTrue($enumSet->contains($enum4));
308
        
309
        $this->assertSame(4, $enumSet->count());
310
311
        $this->assertNull($enumSet->detach($enum2));
312
        $this->assertSame("\x01\x80\x00\x00\x00\x00\x00\x00\x01", $enumSet->getBinaryBitsetBe());
313
        $this->assertFalse($enumSet->contains($enum2));
314
        
315
        $this->assertSame(3, $enumSet->count());
316
    }
317
318 View Code Duplication
    public function testSetBinaryBitsetLe()
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...
319
    {
320
        $enumSet = new EnumSet(Enum65::class);
321
        $enumSet->setBinaryBitsetLe("\x01\x00\x00\x00\x00\x00\x00\x80\x01");
322
323
        $this->assertTrue($enumSet->contains(Enum65::ONE));
324
        $this->assertFalse($enumSet->contains(Enum65::TWO));
325
        $this->assertTrue($enumSet->contains(Enum65::SIXTYFIVE));
326
        $this->assertTrue($enumSet->contains(Enum65::SIXTYFOUR));
327
        $this->assertTrue($enumSet->count() == 3);
328
    }
329
330
    public function testSetBinaryBitsetLeShort()
331
    {
332
        $enumSet = new EnumSet(Enum65::class);
333
        $enumSet->setBinaryBitsetLe("\x0A");
334
        $this->assertSame("\x0A\x00\x00\x00\x00\x00\x00\x00\x00", $enumSet->getBinaryBitsetLe());
335
    }
336
337
    public function testSetBinaryBitsetLeLong()
338
    {
339
        $enumSet = new EnumSet(EnumBasic::class);
340
        $enumSet->setBinaryBitsetLe("\x0A\xFF\x00\x00\x00\x00");
341
        $this->assertSame("\x0A\xFF", $enumSet->getBinaryBitsetLe());
342
    }
343
344
    public function testSetBinaryBitsetLeOutOrRangeBitsOfExtendedBytes1()
345
    {
346
        $enumSet = new EnumSet(EnumBasic::class);
347
348
        $this->setExpectedException(InvalidArgumentException::class, 'Out-Of-Range');
349
        $enumSet->setBinaryBitsetLe("\x0A\xFF\x01");
350
    }
351
352
    public function testSetBinaryBitsetLeOutOrRangeBitsOfExtendedBytes2()
353
    {
354
        $enumSet = new EnumSet(EnumBasic::class);
355
356
        $this->setExpectedException(InvalidArgumentException::class, 'Out-Of-Range');
357
        $enumSet->setBinaryBitsetLe("\x0A\xFF\x00\x02");
358
    }
359
360
    public function testSetBinaryBitsetLeOutOrRangeBitsOfLastValidByte()
361
    {
362
        // using Enum65 to detect Out-Of-Range bits of last valid byte
363
        // Enum65 has max. ordinal number of 2 of the last byte. -> 0001
364
        $enumSet   = new EnumSet(Enum65::class);
365
        $bitset    = $enumSet->getBinaryBitsetLe();
366
        $newBitset = substr($bitset, 0, -1) . "\x02";
367
368
        $this->setExpectedException(InvalidArgumentException::class, 'Out-Of-Range');
369
        $enumSet->setBinaryBitsetLe($newBitset);
370
    }
371
372
    public function testSetBinaryBitsetLeArgumentExceptionIfNotString()
373
    {
374
        $this->setExpectedException(InvalidArgumentException::class);
375
        
376
        $enum = new EnumSet(Enum65::class);
377
        $enum->setBinaryBitsetLe(0);
378
    }
379
380 View Code Duplication
    public function testSetBinaryBitsetBe()
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...
381
    {
382
        $enumSet = new EnumSet(Enum65::class);
383
        $enumSet->setBinaryBitsetBe("\x01\x80\x00\x00\x00\x00\x00\x00\x01");
384
385
        $this->assertTrue($enumSet->contains(Enum65::ONE));
386
        $this->assertFalse($enumSet->contains(Enum65::TWO));
387
        $this->assertTrue($enumSet->contains(Enum65::SIXTYFIVE));
388
        $this->assertTrue($enumSet->contains(Enum65::SIXTYFOUR));
389
        $this->assertTrue($enumSet->count() == 3);
390
    }
391
392
    public function testSetBinaryBitsetBeArgumentExceptionIfNotString()
393
    {
394
        $this->setExpectedException(InvalidArgumentException::class);
395
        
396
        $enum = new EnumSet(Enum65::class);
397
        $enum->setBinaryBitsetBe(0);
398
    }
399
400
    public function testCountingEmptyEnumEmptySet()
401
    {
402
        $set = new EnumSet(EmptyEnum::class);
403
        $this->assertSame(0, $set->count());
404
    }
405
406 View Code Duplication
    public function testIsEqual()
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...
407
    {
408
        $set1 = new EnumSet(EnumBasic::class);
409
        $set2 = new EnumSet(EnumBasic::class);
410
        $this->assertTrue($set1->isEqual($set2));
411
412
        foreach (EnumBasic::getEnumerators() as $enumerator) {
413
            $set1->attach($enumerator);
414
            $this->assertFalse($set1->isEqual($set2));
415
416
            $set2->attach($enumerator);
417
            $this->assertTrue($set1->isEqual($set2));
418
        }
419
    }
420
421 View Code Duplication
    public function testIsEqualWrongInstance()
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...
422
    {
423
        $set1 = new EnumSet(EnumBasic::class);
424
        $set2 = new EnumSet(EnumInheritance::class);
425
        $this->assertFalse($set1->isEqual($set2));
426
427
        foreach (EnumBasic::getEnumerators() as $enumerator) {
428
            $set1->attach($enumerator);
429
            $this->assertFalse($set1->isEqual($set2));
430
431
            $set2->attach($enumerator->getValue());
432
            $this->assertFalse($set1->isEqual($set2));
433
        }
434
    }
435
436
    /**
437
     * if $A->isEqual($B) is true then $A->isSubsetOf($B) is also true
438
     */
439 View Code Duplication
    public function testIsSubsetEqual()
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...
440
    {
441
        $set1 = new EnumSet(Enum32::class);
442
        $set2 = new EnumSet(Enum32::class);
443
        $this->assertTrue($set1->isSubset($set2));
444
445
        foreach (Enum32::getEnumerators() as $enumerator) {
446
            $set1->attach($enumerator);
447
            $set2->attach($enumerator);
448
            $this->assertTrue($set1->isSubset($set2));
449
        }
450
    }
451
452 View Code Duplication
    public function testIsSubsetFull()
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...
453
    {
454
        $set1 = new EnumSet(Enum32::class);
455
        $set2 = new EnumSet(Enum32::class);
456
457
        foreach (Enum32::getEnumerators() as $enumerator) {
458
            $set2->attach($enumerator);
459
            $this->assertTrue($set1->isSubset($set2));
460
        }
461
    }
462
463 View Code Duplication
    public function testIsSubsetFalse()
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...
464
    {
465
        $set1 = new EnumSet(Enum32::class);
466
        $set2 = new EnumSet(Enum32::class);
467
468
        foreach (Enum32::getEnumerators() as $enumerator) {
469
            $set1->attach($enumerator);
470
            $this->assertFalse($set1->isSubset($set2));
471
        }
472
    }
473
474 View Code Duplication
    public function testIsSubsetWrongInstance()
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...
475
    {
476
        $set1 = new EnumSet(EnumBasic::class);
477
        $set2 = new EnumSet(EnumInheritance::class);
478
        $this->assertFalse($set1->isSubset($set2));
479
480
        foreach (EnumBasic::getEnumerators() as $enumerator) {
481
            $set1->attach($enumerator);
482
            $this->assertFalse($set1->isSubset($set2));
483
484
            $set2->attach($enumerator->getValue());
485
            $this->assertFalse($set1->isSubset($set2));
486
        }
487
    }
488
489
    /**
490
     * if $A->isEqual($B) is true then $A->isSuperset($B) is also true
491
     */
492 View Code Duplication
    public function testIsSsetEqual()
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...
493
    {
494
        $set1 = new EnumSet(Enum32::class);
495
        $set2 = new EnumSet(Enum32::class);
496
        $this->assertTrue($set1->isSuperset($set2));
497
498
        foreach (Enum32::getEnumerators() as $enumerator) {
499
            $set1->attach($enumerator);
500
            $set2->attach($enumerator);
501
            $this->assertTrue($set1->isSuperset($set2));
502
        }
503
    }
504
505 View Code Duplication
    public function testIsSupersetFull()
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...
506
    {
507
        $set1 = new EnumSet(Enum32::class);
508
        $set2 = new EnumSet(Enum32::class);
509
510
        foreach (Enum32::getEnumerators() as $enumerator) {
511
            $set1->attach($enumerator);
512
            $this->assertTrue($set1->isSuperset($set2));
513
        }
514
    }
515
516 View Code Duplication
    public function testIsSupersetFalse()
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...
517
    {
518
        $set1 = new EnumSet(Enum32::class);
519
        $set2 = new EnumSet(Enum32::class);
520
521
        foreach (Enum32::getEnumerators() as $enumerator) {
522
            $set2->attach($enumerator);
523
            $this->assertFalse($set1->isSuperset($set2));
524
        }
525
    }
526
527 View Code Duplication
    public function testIsSupersetWrongInstance()
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...
528
    {
529
        $set1 = new EnumSet(EnumBasic::class);
530
        $set2 = new EnumSet(EnumInheritance::class);
531
        $this->assertFalse($set1->isSuperset($set2));
532
533
        foreach (EnumBasic::getEnumerators() as $enumerator) {
534
            $set1->attach($enumerator);
535
            $this->assertFalse($set1->isSuperset($set2));
536
537
            $set2->attach($enumerator->getValue());
538
            $this->assertFalse($set1->isSuperset($set2));
539
        }
540
    }
541
542
    public function testGetOrdinals()
543
    {
544
        $set = new EnumSet(EnumBasic::class);
545
        $this->assertSame(array(), $set->getOrdinals());
546
547
        foreach (EnumBasic::getConstants() as $value) {
548
            $set->attach($value);
549
        }
550
551
        $this->assertSame(range(0, count(EnumBasic::getConstants()) - 1), $set->getOrdinals());
552
    }
553
554 View Code Duplication
    public function testGetOrdinalsDoesNotEffectIteratorPosition()
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...
555
    {
556
        $set = new EnumSet(EnumBasic::class);
557
        $set->attach(EnumBasic::ONE);
558
        $set->attach(EnumBasic::TWO);
559
        $set->next();
560
561
        $set->getOrdinals();
562
        $this->assertSame(EnumBasic::TWO, $set->current()->getValue());
563
    }
564
565 View Code Duplication
    public function testGetEnumerators()
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...
566
    {
567
        $set = new EnumSet(EnumBasic::class);
568
        $this->assertSame(array(), $set->getEnumerators());
569
570
        foreach (EnumBasic::getConstants() as $value) {
571
            $set->attach($value);
572
        }
573
574
        $this->assertSame(EnumBasic::getEnumerators(), $set->getEnumerators());
575
    }
576
577 View Code Duplication
    public function testGetEnumeratorsDoesNotEffectIteratorPosition()
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...
578
    {
579
        $set = new EnumSet(EnumBasic::class);
580
        $set->attach(EnumBasic::ONE);
581
        $set->attach(EnumBasic::TWO);
582
        $set->next();
583
584
        $set->getEnumerators();
585
        $this->assertSame(EnumBasic::TWO, $set->current()->getValue());
586
    }
587
588 View Code Duplication
    public function testGetValues()
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...
589
    {
590
        $set = new EnumSet(EnumBasic::class);
591
        $this->assertSame(array(), $set->getValues());
592
593
        foreach (EnumBasic::getConstants() as $value) {
594
            $set->attach($value);
595
        }
596
597
        $this->assertSame(array_values(EnumBasic::getConstants()), $set->getValues());
598
    }
599
600 View Code Duplication
    public function testGetValuesDoesNotEffectIteratorPosition()
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...
601
    {
602
        $set = new EnumSet(EnumBasic::class);
603
        $set->attach(EnumBasic::ONE);
604
        $set->attach(EnumBasic::TWO);
605
        $set->next();
606
607
        $set->getValues();
608
        $this->assertSame(EnumBasic::TWO, $set->current()->getValue());
609
    }
610
611 View Code Duplication
    public function testGetNames()
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...
612
    {
613
        $set = new EnumSet(EnumBasic::class);
614
        $this->assertSame(array(), $set->getNames());
615
616
        foreach (EnumBasic::getConstants() as $value) {
617
            $set->attach($value);
618
        }
619
620
        $this->assertSame(array_keys(EnumBasic::getConstants()), $set->getNames());
621
    }
622
623 View Code Duplication
    public function testGetNamesDoesNotEffectIteratorPosition()
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...
624
    {
625
        $set = new EnumSet(EnumBasic::class);
626
        $set->attach(EnumBasic::ONE);
627
        $set->attach(EnumBasic::TWO);
628
        $set->next();
629
630
        $set->getNames();
631
        $this->assertSame(EnumBasic::TWO, $set->current()->getValue());
632
    }
633
634
    public function testUnion()
635
    {
636
        $set1 = new EnumSet(EnumBasic::class);
637
        $set1->attach(EnumBasic::ONE);
638
        $set1->attach(EnumBasic::TWO);
639
640
        $set2 = new EnumSet(EnumBasic::class);
641
        $set2->attach(EnumBasic::TWO);
642
        $set2->attach(EnumBasic::THREE);
643
644
        $set3 = new EnumSet(EnumBasic::class);
645
        $set3->attach(EnumBasic::THREE);
646
        $set3->attach(EnumBasic::FOUR);
647
648
        $rs = $set1->union($set2, $set3);
649
        $this->assertSame(array(
650
            EnumBasic::ONE,
651
            EnumBasic::TWO,
652
            EnumBasic::THREE,
653
            EnumBasic::FOUR,
654
        ), $rs->getValues());
655
    }
656
657 View Code Duplication
    public function testUnionThrowsInvalidArgumentException()
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...
658
    {
659
        $set1 = new EnumSet(EnumBasic::class);
660
        $set2 = new EnumSet(Enum32::class);
661
662
        $this->setExpectedException(InvalidArgumentException::class);
663
        $set1->union($set2);
664
    }
665
666 View Code Duplication
    public function testIntersect()
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...
667
    {
668
        $set1 = new EnumSet(EnumBasic::class);
669
        $set1->attach(EnumBasic::ONE);
670
        $set1->attach(EnumBasic::TWO);
671
        $set1->attach(EnumBasic::THREE);
672
673
        $set2 = new EnumSet(EnumBasic::class);
674
        $set2->attach(EnumBasic::TWO);
675
        $set2->attach(EnumBasic::THREE);
676
        $set2->attach(EnumBasic::FOUR);
677
678
        $set3 = new EnumSet(EnumBasic::class);
679
        $set3->attach(EnumBasic::THREE);
680
        $set3->attach(EnumBasic::FOUR);
681
        $set3->attach(EnumBasic::FIVE);
682
683
        $rs = $set1->intersect($set2, $set3);
684
        $this->assertSame(array(
685
            EnumBasic::THREE,
686
        ), $rs->getValues());
687
    }
688
689 View Code Duplication
    public function testIntersectThrowsInvalidArgumentException()
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...
690
    {
691
        $set1 = new EnumSet(EnumBasic::class);
692
        $set2 = new EnumSet(Enum32::class);
693
694
        $this->setExpectedException(InvalidArgumentException::class);
695
        $set1->intersect($set2);
696
    }
697
698 View Code Duplication
    public function testDiff()
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...
699
    {
700
        $set1 = new EnumSet(EnumBasic::class);
701
        $set1->attach(EnumBasic::ONE);
702
        $set1->attach(EnumBasic::TWO);
703
        $set1->attach(EnumBasic::THREE);
704
705
        $set2 = new EnumSet(EnumBasic::class);
706
        $set2->attach(EnumBasic::TWO);
707
        $set2->attach(EnumBasic::THREE);
708
        $set2->attach(EnumBasic::FOUR);
709
710
        $set3 = new EnumSet(EnumBasic::class);
711
        $set3->attach(EnumBasic::THREE);
712
        $set3->attach(EnumBasic::FOUR);
713
        $set3->attach(EnumBasic::FIVE);
714
715
        $rs = $set1->diff($set2, $set3);
716
        $this->assertSame(array(
717
            EnumBasic::ONE,
718
        ), $rs->getValues());
719
    }
720
721 View Code Duplication
    public function testDiffThrowsInvalidArgumentException()
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...
722
    {
723
        $set1 = new EnumSet(EnumBasic::class);
724
        $set2 = new EnumSet(Enum32::class);
725
726
        $this->setExpectedException(InvalidArgumentException::class);
727
        $set1->diff($set2);
728
    }
729
730
    public function testSymDiff()
731
    {
732
        $set1 = new EnumSet(EnumBasic::class);
733
        $set1->attach(EnumBasic::ONE);
734
        $set1->attach(EnumBasic::TWO);
735
        $set1->attach(EnumBasic::THREE);
736
737
        $set2 = new EnumSet(EnumBasic::class);
738
        $set2->attach(EnumBasic::TWO);
739
        $set2->attach(EnumBasic::THREE);
740
        $set2->attach(EnumBasic::FOUR);
741
742
        $set3 = new EnumSet(EnumBasic::class);
743
        $set3->attach(EnumBasic::THREE);
744
        $set3->attach(EnumBasic::FOUR);
745
        $set3->attach(EnumBasic::FIVE);
746
747
        $rs = $set1->symDiff($set2, $set3);
748
        $this->assertSame(array(
749
            EnumBasic::ONE,
750
            EnumBasic::FOUR,
751
            EnumBasic::FIVE,
752
        ), $rs->getValues());
753
    }
754
755 View Code Duplication
    public function testSymDiffThrowsInvalidArgumentException()
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...
756
    {
757
        $set1 = new EnumSet(EnumBasic::class);
758
        $set2 = new EnumSet(Enum32::class);
759
760
        $this->setExpectedException(InvalidArgumentException::class);
761
        $set1->symDiff($set2);
762
    }
763
}
764