Completed
Push — master ( a7a3d5...1aa683 )
by Marc
01:41
created

EnumSetTest::testGetBitset()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 23

Duplication

Lines 33
Ratio 100 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
dl 33
loc 33
rs 8.8571
c 2
b 1
f 0
cc 1
eloc 23
nc 1
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A EnumSetTest::testSetBinaryBitsetLeTruncateHighBits() 0 16 2
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 testSetBinaryBitsetLeTruncateHighBits()
331
    {
332
        // using Enum66 to make sure the max. ordinal number gets converted into a bitset
333
        // Enum65 has max. ordinal number of 1 of the last byte. -> 00000001
334
        // Enum66 has max. ordinal number of 2 of the last byte. -> 00000011
335
        $enumSet = new EnumSet(Enum66::class);
336
        foreach (Enum66::getEnumerators() as $enumerator) {
337
            $enumSet->attach($enumerator);
338
        }
339
340
        $bitset    = $enumSet->getBinaryBitsetLe();
341
        $newBitset = substr($bitset, 0, -1) . "\xff\xff";
342
        $enumSet->setBinaryBitsetLe($newBitset);
343
344
        $this->assertSame(bin2hex($bitset), bin2hex($enumSet->getBinaryBitsetLe()));
345
    }
346
347 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...
348
    {
349
        $enumSet = new EnumSet(Enum65::class);
350
        $enumSet->setBinaryBitsetBe("\x01\x80\x00\x00\x00\x00\x00\x00\x01");
351
352
        $this->assertTrue($enumSet->contains(Enum65::ONE));
353
        $this->assertFalse($enumSet->contains(Enum65::TWO));
354
        $this->assertTrue($enumSet->contains(Enum65::SIXTYFIVE));
355
        $this->assertTrue($enumSet->contains(Enum65::SIXTYFOUR));
356
        $this->assertTrue($enumSet->count() == 3);
357
    }
358
359
    public function testSetBinaryBitsetLeShort()
360
    {
361
        $enumSet = new EnumSet(Enum65::class);
362
        $enumSet->setBinaryBitsetLe("\x0A");
363
        $this->assertSame("\x0A\x00\x00\x00\x00\x00\x00\x00\x00", $enumSet->getBinaryBitsetLe());
364
    }
365
366
    public function testSetBinaryBitsetLeLong()
367
    {
368
        $enumSet = new EnumSet(EnumBasic::class);
369
        $enumSet->setBinaryBitsetLe("\x0A\xFF\xFF\xFF\xFF\xFF");
370
        $this->assertSame("\x0A\xFF", $enumSet->getBinaryBitsetLe());
371
    }
372
373
    public function testSetBinaryBitsetLeArgumentExceptionIfNotString()
374
    {
375
        $this->setExpectedException(InvalidArgumentException::class);
376
        
377
        $enum = new EnumSet(Enum65::class);
378
        $enum->setBinaryBitsetLe(0);
379
    }
380
381
    public function testSetBinaryBitsetBeArgumentExceptionIfNotString()
382
    {
383
        $this->setExpectedException(InvalidArgumentException::class);
384
        
385
        $enum = new EnumSet(Enum65::class);
386
        $enum->setBinaryBitsetBe(0);
387
    }
388
389
    public function testCountingEmptyEnumEmptySet()
390
    {
391
        $set = new EnumSet(EmptyEnum::class);
392
        $this->assertSame(0, $set->count());
393
    }
394
395 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...
396
    {
397
        $set1 = new EnumSet(EnumBasic::class);
398
        $set2 = new EnumSet(EnumBasic::class);
399
        $this->assertTrue($set1->isEqual($set2));
400
401
        foreach (EnumBasic::getEnumerators() as $enumerator) {
402
            $set1->attach($enumerator);
403
            $this->assertFalse($set1->isEqual($set2));
404
405
            $set2->attach($enumerator);
406
            $this->assertTrue($set1->isEqual($set2));
407
        }
408
    }
409
410 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...
411
    {
412
        $set1 = new EnumSet(EnumBasic::class);
413
        $set2 = new EnumSet(EnumInheritance::class);
414
        $this->assertFalse($set1->isEqual($set2));
415
416
        foreach (EnumBasic::getEnumerators() as $enumerator) {
417
            $set1->attach($enumerator);
418
            $this->assertFalse($set1->isEqual($set2));
419
420
            $set2->attach($enumerator->getValue());
421
            $this->assertFalse($set1->isEqual($set2));
422
        }
423
    }
424
425
    /**
426
     * if $A->isEqual($B) is true then $A->isSubsetOf($B) is also true
427
     */
428 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...
429
    {
430
        $set1 = new EnumSet(Enum32::class);
431
        $set2 = new EnumSet(Enum32::class);
432
        $this->assertTrue($set1->isSubset($set2));
433
434
        foreach (Enum32::getEnumerators() as $enumerator) {
435
            $set1->attach($enumerator);
436
            $set2->attach($enumerator);
437
            $this->assertTrue($set1->isSubset($set2));
438
        }
439
    }
440
441 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...
442
    {
443
        $set1 = new EnumSet(Enum32::class);
444
        $set2 = new EnumSet(Enum32::class);
445
446
        foreach (Enum32::getEnumerators() as $enumerator) {
447
            $set2->attach($enumerator);
448
            $this->assertTrue($set1->isSubset($set2));
449
        }
450
    }
451
452 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...
453
    {
454
        $set1 = new EnumSet(Enum32::class);
455
        $set2 = new EnumSet(Enum32::class);
456
457
        foreach (Enum32::getEnumerators() as $enumerator) {
458
            $set1->attach($enumerator);
459
            $this->assertFalse($set1->isSubset($set2));
460
        }
461
    }
462
463 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...
464
    {
465
        $set1 = new EnumSet(EnumBasic::class);
466
        $set2 = new EnumSet(EnumInheritance::class);
467
        $this->assertFalse($set1->isSubset($set2));
468
469
        foreach (EnumBasic::getEnumerators() as $enumerator) {
470
            $set1->attach($enumerator);
471
            $this->assertFalse($set1->isSubset($set2));
472
473
            $set2->attach($enumerator->getValue());
474
            $this->assertFalse($set1->isSubset($set2));
475
        }
476
    }
477
478
    /**
479
     * if $A->isEqual($B) is true then $A->isSuperset($B) is also true
480
     */
481 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...
482
    {
483
        $set1 = new EnumSet(Enum32::class);
484
        $set2 = new EnumSet(Enum32::class);
485
        $this->assertTrue($set1->isSuperset($set2));
486
487
        foreach (Enum32::getEnumerators() as $enumerator) {
488
            $set1->attach($enumerator);
489
            $set2->attach($enumerator);
490
            $this->assertTrue($set1->isSuperset($set2));
491
        }
492
    }
493
494 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...
495
    {
496
        $set1 = new EnumSet(Enum32::class);
497
        $set2 = new EnumSet(Enum32::class);
498
499
        foreach (Enum32::getEnumerators() as $enumerator) {
500
            $set1->attach($enumerator);
501
            $this->assertTrue($set1->isSuperset($set2));
502
        }
503
    }
504
505 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...
506
    {
507
        $set1 = new EnumSet(Enum32::class);
508
        $set2 = new EnumSet(Enum32::class);
509
510
        foreach (Enum32::getEnumerators() as $enumerator) {
511
            $set2->attach($enumerator);
512
            $this->assertFalse($set1->isSuperset($set2));
513
        }
514
    }
515
516 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...
517
    {
518
        $set1 = new EnumSet(EnumBasic::class);
519
        $set2 = new EnumSet(EnumInheritance::class);
520
        $this->assertFalse($set1->isSuperset($set2));
521
522
        foreach (EnumBasic::getEnumerators() as $enumerator) {
523
            $set1->attach($enumerator);
524
            $this->assertFalse($set1->isSuperset($set2));
525
526
            $set2->attach($enumerator->getValue());
527
            $this->assertFalse($set1->isSuperset($set2));
528
        }
529
    }
530
531
    public function testGetOrdinals()
532
    {
533
        $set = new EnumSet(EnumBasic::class);
534
        $this->assertSame(array(), $set->getOrdinals());
535
536
        foreach (EnumBasic::getConstants() as $value) {
537
            $set->attach($value);
538
        }
539
540
        $this->assertSame(range(0, count(EnumBasic::getConstants()) - 1), $set->getOrdinals());
541
    }
542
543 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...
544
    {
545
        $set = new EnumSet(EnumBasic::class);
546
        $set->attach(EnumBasic::ONE);
547
        $set->attach(EnumBasic::TWO);
548
        $set->next();
549
550
        $set->getOrdinals();
551
        $this->assertSame(EnumBasic::TWO, $set->current()->getValue());
552
    }
553
554 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...
555
    {
556
        $set = new EnumSet(EnumBasic::class);
557
        $this->assertSame(array(), $set->getEnumerators());
558
559
        foreach (EnumBasic::getConstants() as $value) {
560
            $set->attach($value);
561
        }
562
563
        $this->assertSame(EnumBasic::getEnumerators(), $set->getEnumerators());
564
    }
565
566 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...
567
    {
568
        $set = new EnumSet(EnumBasic::class);
569
        $set->attach(EnumBasic::ONE);
570
        $set->attach(EnumBasic::TWO);
571
        $set->next();
572
573
        $set->getEnumerators();
574
        $this->assertSame(EnumBasic::TWO, $set->current()->getValue());
575
    }
576
577 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...
578
    {
579
        $set = new EnumSet(EnumBasic::class);
580
        $this->assertSame(array(), $set->getValues());
581
582
        foreach (EnumBasic::getConstants() as $value) {
583
            $set->attach($value);
584
        }
585
586
        $this->assertSame(array_values(EnumBasic::getConstants()), $set->getValues());
587
    }
588
589 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...
590
    {
591
        $set = new EnumSet(EnumBasic::class);
592
        $set->attach(EnumBasic::ONE);
593
        $set->attach(EnumBasic::TWO);
594
        $set->next();
595
596
        $set->getValues();
597
        $this->assertSame(EnumBasic::TWO, $set->current()->getValue());
598
    }
599
600 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...
601
    {
602
        $set = new EnumSet(EnumBasic::class);
603
        $this->assertSame(array(), $set->getNames());
604
605
        foreach (EnumBasic::getConstants() as $value) {
606
            $set->attach($value);
607
        }
608
609
        $this->assertSame(array_keys(EnumBasic::getConstants()), $set->getNames());
610
    }
611
612 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...
613
    {
614
        $set = new EnumSet(EnumBasic::class);
615
        $set->attach(EnumBasic::ONE);
616
        $set->attach(EnumBasic::TWO);
617
        $set->next();
618
619
        $set->getNames();
620
        $this->assertSame(EnumBasic::TWO, $set->current()->getValue());
621
    }
622
623
    public function testUnion()
624
    {
625
        $set1 = new EnumSet(EnumBasic::class);
626
        $set1->attach(EnumBasic::ONE);
627
        $set1->attach(EnumBasic::TWO);
628
629
        $set2 = new EnumSet(EnumBasic::class);
630
        $set2->attach(EnumBasic::TWO);
631
        $set2->attach(EnumBasic::THREE);
632
633
        $set3 = new EnumSet(EnumBasic::class);
634
        $set3->attach(EnumBasic::THREE);
635
        $set3->attach(EnumBasic::FOUR);
636
637
        $rs = $set1->union($set2, $set3);
638
        $this->assertSame(array(
639
            EnumBasic::ONE,
640
            EnumBasic::TWO,
641
            EnumBasic::THREE,
642
            EnumBasic::FOUR,
643
        ), $rs->getValues());
644
    }
645
646 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...
647
    {
648
        $set1 = new EnumSet(EnumBasic::class);
649
        $set2 = new EnumSet(Enum32::class);
650
651
        $this->setExpectedException(InvalidArgumentException::class);
652
        $set1->union($set2);
653
    }
654
655 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...
656
    {
657
        $set1 = new EnumSet(EnumBasic::class);
658
        $set1->attach(EnumBasic::ONE);
659
        $set1->attach(EnumBasic::TWO);
660
        $set1->attach(EnumBasic::THREE);
661
662
        $set2 = new EnumSet(EnumBasic::class);
663
        $set2->attach(EnumBasic::TWO);
664
        $set2->attach(EnumBasic::THREE);
665
        $set2->attach(EnumBasic::FOUR);
666
667
        $set3 = new EnumSet(EnumBasic::class);
668
        $set3->attach(EnumBasic::THREE);
669
        $set3->attach(EnumBasic::FOUR);
670
        $set3->attach(EnumBasic::FIVE);
671
672
        $rs = $set1->intersect($set2, $set3);
673
        $this->assertSame(array(
674
            EnumBasic::THREE,
675
        ), $rs->getValues());
676
    }
677
678 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...
679
    {
680
        $set1 = new EnumSet(EnumBasic::class);
681
        $set2 = new EnumSet(Enum32::class);
682
683
        $this->setExpectedException(InvalidArgumentException::class);
684
        $set1->intersect($set2);
685
    }
686
687 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...
688
    {
689
        $set1 = new EnumSet(EnumBasic::class);
690
        $set1->attach(EnumBasic::ONE);
691
        $set1->attach(EnumBasic::TWO);
692
        $set1->attach(EnumBasic::THREE);
693
694
        $set2 = new EnumSet(EnumBasic::class);
695
        $set2->attach(EnumBasic::TWO);
696
        $set2->attach(EnumBasic::THREE);
697
        $set2->attach(EnumBasic::FOUR);
698
699
        $set3 = new EnumSet(EnumBasic::class);
700
        $set3->attach(EnumBasic::THREE);
701
        $set3->attach(EnumBasic::FOUR);
702
        $set3->attach(EnumBasic::FIVE);
703
704
        $rs = $set1->diff($set2, $set3);
705
        $this->assertSame(array(
706
            EnumBasic::ONE,
707
        ), $rs->getValues());
708
    }
709
710 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...
711
    {
712
        $set1 = new EnumSet(EnumBasic::class);
713
        $set2 = new EnumSet(Enum32::class);
714
715
        $this->setExpectedException(InvalidArgumentException::class);
716
        $set1->diff($set2);
717
    }
718
719
    public function testSymDiff()
720
    {
721
        $set1 = new EnumSet(EnumBasic::class);
722
        $set1->attach(EnumBasic::ONE);
723
        $set1->attach(EnumBasic::TWO);
724
        $set1->attach(EnumBasic::THREE);
725
726
        $set2 = new EnumSet(EnumBasic::class);
727
        $set2->attach(EnumBasic::TWO);
728
        $set2->attach(EnumBasic::THREE);
729
        $set2->attach(EnumBasic::FOUR);
730
731
        $set3 = new EnumSet(EnumBasic::class);
732
        $set3->attach(EnumBasic::THREE);
733
        $set3->attach(EnumBasic::FOUR);
734
        $set3->attach(EnumBasic::FIVE);
735
736
        $rs = $set1->symDiff($set2, $set3);
737
        $this->assertSame(array(
738
            EnumBasic::ONE,
739
            EnumBasic::FOUR,
740
            EnumBasic::FIVE,
741
        ), $rs->getValues());
742
    }
743
744 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...
745
    {
746
        $set1 = new EnumSet(EnumBasic::class);
747
        $set2 = new EnumSet(Enum32::class);
748
749
        $this->setExpectedException(InvalidArgumentException::class);
750
        $set1->symDiff($set2);
751
    }
752
}
753