Completed
Push — master ( 5da858...2241f0 )
by Marc
01:31
created

EnumSetTest::testIsSupersetIsEqual()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 14
loc 14
rs 9.4285
cc 2
eloc 10
nc 2
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 testIsSubsetIsEqual()
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 testIsSupersetIsEqual()
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->isEqual($set2));
497
        $this->assertTrue($set1->isSuperset($set2));
498
499
        foreach (Enum32::getEnumerators() as $enumerator) {
500
            $set1->attach($enumerator);
501
            $set2->attach($enumerator);
502
            $this->assertTrue($set1->isEqual($set2));
503
            $this->assertTrue($set1->isSuperset($set2));
504
        }
505
    }
506
507 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...
508
    {
509
        $set1 = new EnumSet(Enum32::class);
510
        $set2 = new EnumSet(Enum32::class);
511
512
        foreach (Enum32::getEnumerators() as $enumerator) {
513
            $set1->attach($enumerator);
514
            $this->assertTrue($set1->isSuperset($set2));
515
        }
516
    }
517
518 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...
519
    {
520
        $set1 = new EnumSet(Enum32::class);
521
        $set2 = new EnumSet(Enum32::class);
522
523
        foreach (Enum32::getEnumerators() as $enumerator) {
524
            $set2->attach($enumerator);
525
            $this->assertFalse($set1->isSuperset($set2));
526
        }
527
    }
528
529 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...
530
    {
531
        $set1 = new EnumSet(EnumBasic::class);
532
        $set2 = new EnumSet(EnumInheritance::class);
533
        $this->assertFalse($set1->isSuperset($set2));
534
535
        foreach (EnumBasic::getEnumerators() as $enumerator) {
536
            $set1->attach($enumerator);
537
            $this->assertFalse($set1->isSuperset($set2));
538
539
            $set2->attach($enumerator->getValue());
540
            $this->assertFalse($set1->isSuperset($set2));
541
        }
542
    }
543
544
    public function testGetOrdinals()
545
    {
546
        $set = new EnumSet(EnumBasic::class);
547
        $this->assertSame(array(), $set->getOrdinals());
548
549
        foreach (EnumBasic::getConstants() as $value) {
550
            $set->attach($value);
551
        }
552
553
        $this->assertSame(range(0, count(EnumBasic::getConstants()) - 1), $set->getOrdinals());
554
    }
555
556 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...
557
    {
558
        $set = new EnumSet(EnumBasic::class);
559
        $set->attach(EnumBasic::ONE);
560
        $set->attach(EnumBasic::TWO);
561
        $set->next();
562
563
        $set->getOrdinals();
564
        $this->assertSame(EnumBasic::TWO, $set->current()->getValue());
565
    }
566
567 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...
568
    {
569
        $set = new EnumSet(EnumBasic::class);
570
        $this->assertSame(array(), $set->getEnumerators());
571
572
        foreach (EnumBasic::getConstants() as $value) {
573
            $set->attach($value);
574
        }
575
576
        $this->assertSame(EnumBasic::getEnumerators(), $set->getEnumerators());
577
    }
578
579 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...
580
    {
581
        $set = new EnumSet(EnumBasic::class);
582
        $set->attach(EnumBasic::ONE);
583
        $set->attach(EnumBasic::TWO);
584
        $set->next();
585
586
        $set->getEnumerators();
587
        $this->assertSame(EnumBasic::TWO, $set->current()->getValue());
588
    }
589
590 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...
591
    {
592
        $set = new EnumSet(EnumBasic::class);
593
        $this->assertSame(array(), $set->getValues());
594
595
        foreach (EnumBasic::getConstants() as $value) {
596
            $set->attach($value);
597
        }
598
599
        $this->assertSame(array_values(EnumBasic::getConstants()), $set->getValues());
600
    }
601
602 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...
603
    {
604
        $set = new EnumSet(EnumBasic::class);
605
        $set->attach(EnumBasic::ONE);
606
        $set->attach(EnumBasic::TWO);
607
        $set->next();
608
609
        $set->getValues();
610
        $this->assertSame(EnumBasic::TWO, $set->current()->getValue());
611
    }
612
613 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...
614
    {
615
        $set = new EnumSet(EnumBasic::class);
616
        $this->assertSame(array(), $set->getNames());
617
618
        foreach (EnumBasic::getConstants() as $value) {
619
            $set->attach($value);
620
        }
621
622
        $this->assertSame(array_keys(EnumBasic::getConstants()), $set->getNames());
623
    }
624
625 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...
626
    {
627
        $set = new EnumSet(EnumBasic::class);
628
        $set->attach(EnumBasic::ONE);
629
        $set->attach(EnumBasic::TWO);
630
        $set->next();
631
632
        $set->getNames();
633
        $this->assertSame(EnumBasic::TWO, $set->current()->getValue());
634
    }
635
636
    public function testUnion()
637
    {
638
        $set1 = new EnumSet(EnumBasic::class);
639
        $set1->attach(EnumBasic::ONE);
640
        $set1->attach(EnumBasic::TWO);
641
642
        $set2 = new EnumSet(EnumBasic::class);
643
        $set2->attach(EnumBasic::TWO);
644
        $set2->attach(EnumBasic::THREE);
645
646
        $set3 = new EnumSet(EnumBasic::class);
647
        $set3->attach(EnumBasic::THREE);
648
        $set3->attach(EnumBasic::FOUR);
649
650
        $rs = $set1->union($set2, $set3);
651
        $this->assertSame(array(
652
            EnumBasic::ONE,
653
            EnumBasic::TWO,
654
            EnumBasic::THREE,
655
            EnumBasic::FOUR,
656
        ), $rs->getValues());
657
    }
658
659 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...
660
    {
661
        $set1 = new EnumSet(EnumBasic::class);
662
        $set2 = new EnumSet(Enum32::class);
663
664
        $this->setExpectedException(InvalidArgumentException::class);
665
        $set1->union($set2);
666
    }
667
668 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...
669
    {
670
        $set1 = new EnumSet(EnumBasic::class);
671
        $set1->attach(EnumBasic::ONE);
672
        $set1->attach(EnumBasic::TWO);
673
        $set1->attach(EnumBasic::THREE);
674
675
        $set2 = new EnumSet(EnumBasic::class);
676
        $set2->attach(EnumBasic::TWO);
677
        $set2->attach(EnumBasic::THREE);
678
        $set2->attach(EnumBasic::FOUR);
679
680
        $set3 = new EnumSet(EnumBasic::class);
681
        $set3->attach(EnumBasic::THREE);
682
        $set3->attach(EnumBasic::FOUR);
683
        $set3->attach(EnumBasic::FIVE);
684
685
        $rs = $set1->intersect($set2, $set3);
686
        $this->assertSame(array(
687
            EnumBasic::THREE,
688
        ), $rs->getValues());
689
    }
690
691 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...
692
    {
693
        $set1 = new EnumSet(EnumBasic::class);
694
        $set2 = new EnumSet(Enum32::class);
695
696
        $this->setExpectedException(InvalidArgumentException::class);
697
        $set1->intersect($set2);
698
    }
699
700 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...
701
    {
702
        $set1 = new EnumSet(EnumBasic::class);
703
        $set1->attach(EnumBasic::ONE);
704
        $set1->attach(EnumBasic::TWO);
705
        $set1->attach(EnumBasic::THREE);
706
707
        $set2 = new EnumSet(EnumBasic::class);
708
        $set2->attach(EnumBasic::TWO);
709
        $set2->attach(EnumBasic::THREE);
710
        $set2->attach(EnumBasic::FOUR);
711
712
        $set3 = new EnumSet(EnumBasic::class);
713
        $set3->attach(EnumBasic::THREE);
714
        $set3->attach(EnumBasic::FOUR);
715
        $set3->attach(EnumBasic::FIVE);
716
717
        $rs = $set1->diff($set2, $set3);
718
        $this->assertSame(array(
719
            EnumBasic::ONE,
720
        ), $rs->getValues());
721
    }
722
723 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...
724
    {
725
        $set1 = new EnumSet(EnumBasic::class);
726
        $set2 = new EnumSet(Enum32::class);
727
728
        $this->setExpectedException(InvalidArgumentException::class);
729
        $set1->diff($set2);
730
    }
731
732
    public function testSymDiff()
733
    {
734
        $set1 = new EnumSet(EnumBasic::class);
735
        $set1->attach(EnumBasic::ONE);
736
        $set1->attach(EnumBasic::TWO);
737
        $set1->attach(EnumBasic::THREE);
738
739
        $set2 = new EnumSet(EnumBasic::class);
740
        $set2->attach(EnumBasic::TWO);
741
        $set2->attach(EnumBasic::THREE);
742
        $set2->attach(EnumBasic::FOUR);
743
744
        $set3 = new EnumSet(EnumBasic::class);
745
        $set3->attach(EnumBasic::THREE);
746
        $set3->attach(EnumBasic::FOUR);
747
        $set3->attach(EnumBasic::FIVE);
748
749
        $rs = $set1->symDiff($set2, $set3);
750
        $this->assertSame(array(
751
            EnumBasic::ONE,
752
            EnumBasic::FOUR,
753
            EnumBasic::FIVE,
754
        ), $rs->getValues());
755
    }
756
757 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...
758
    {
759
        $set1 = new EnumSet(EnumBasic::class);
760
        $set2 = new EnumSet(Enum32::class);
761
762
        $this->setExpectedException(InvalidArgumentException::class);
763
        $set1->symDiff($set2);
764
    }
765
}
766