Completed
Push — master ( 9803f7...848250 )
by Marc
01:37
created

EnumSetTest::test32EnumerationsSet()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 12

Duplication

Lines 18
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 18
loc 18
rs 9.4285
cc 3
eloc 12
nc 4
nop 0
1
<?php
2
3
namespace MabeEnumTest;
4
5
use MabeEnum\EnumSet;
6
use MabeEnumTest\TestAsset\EmptyEnum;
7
use MabeEnumTest\TestAsset\EnumBasic;
8
use MabeEnumTest\TestAsset\EnumInheritance;
9
use MabeEnumTest\TestAsset\Enum32;
10
use MabeEnumTest\TestAsset\Enum64;
11
use MabeEnumTest\TestAsset\Enum65;
12
use MabeEnumTest\TestAsset\Enum66;
13
use PHPUnit_Framework_TestCase as TestCase;
14
15
/**
16
 * Unit tests for the class MabeEnum\EnumSet
17
 *
18
 * @link http://github.com/marc-mabe/php-enum for the canonical source repository
19
 * @copyright Copyright (c) 2015 Marc Bennewitz
20
 * @license http://github.com/marc-mabe/php-enum/blob/master/LICENSE.txt New BSD License
21
 */
22
class EnumSetTest extends TestCase
23
{
24
    public function testBasic()
25
    {
26
        $enumSet = new EnumSet('MabeEnumTest\TestAsset\EnumBasic');
27
        $this->assertSame('MabeEnumTest\TestAsset\EnumBasic', $enumSet->getEnumeration());
28
29
        $enum1  = EnumBasic::ONE();
30
        $enum2  = EnumBasic::TWO();
31
32
        $this->assertFalse($enumSet->contains($enum1));
33
        $this->assertNull($enumSet->attach($enum1));
34
        $this->assertTrue($enumSet->contains($enum1));
35
36
        $this->assertFalse($enumSet->contains($enum2));
37
        $this->assertNull($enumSet->attach($enum2));
38
        $this->assertTrue($enumSet->contains($enum2));
39
40
        $this->assertNull($enumSet->detach($enum1));
41
        $this->assertFalse($enumSet->contains($enum1));
42
43
        $this->assertNull($enumSet->detach($enum2));
44
        $this->assertFalse($enumSet->contains($enum2));
45
    }
46
47
    public function testBasicWithConstantValuesAsEnums()
48
    {
49
        $enumSet = new EnumSet('MabeEnumTest\TestAsset\EnumBasic');
50
51
        $enum1  = EnumBasic::ONE;
52
        $enum2  = EnumBasic::TWO;
53
54
        $this->assertFalse($enumSet->contains($enum1));
55
        $this->assertNull($enumSet->attach($enum1));
56
        $this->assertTrue($enumSet->contains($enum1));
57
58
        $this->assertFalse($enumSet->contains($enum2));
59
        $this->assertNull($enumSet->attach($enum2));
60
        $this->assertTrue($enumSet->contains($enum2));
61
62
        $this->assertNull($enumSet->detach($enum1));
63
        $this->assertFalse($enumSet->contains($enum1));
64
65
        $this->assertNull($enumSet->detach($enum2));
66
        $this->assertFalse($enumSet->contains($enum2));
67
    }
68
69 View Code Duplication
    public function testUnique()
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...
70
    {
71
        $enumSet = new EnumSet('MabeEnumTest\TestAsset\EnumBasic');
72
73
        $enumSet->attach(EnumBasic::ONE());
74
        $enumSet->attach(EnumBasic::ONE);
75
76
        $enumSet->attach(EnumBasic::TWO());
77
        $enumSet->attach(EnumBasic::TWO);
78
79
        $this->assertSame(2, $enumSet->count());
80
    }
81
82
    public function testIterateOrdered()
83
    {
84
        $enumSet = new EnumSet('MabeEnumTest\TestAsset\EnumBasic');
85
86
        // an empty enum set needs to be invalid, starting by 0
87
        $this->assertSame(0, $enumSet->count());
88
        $this->assertFalse($enumSet->valid());
89
        $this->assertNull($enumSet->current());
90
91
        // attach
92
        $enum1 = EnumBasic::ONE();
93
        $enum2 = EnumBasic::TWO();
94
        $enumSet->attach($enum1);
95
        $enumSet->attach($enum2);
96
97
        // a not empty enum set should be valid, starting by 0 (if not iterated)
98
        $enumSet->rewind();
99
        $this->assertSame(2, $enumSet->count());
100
        $this->assertTrue($enumSet->valid());
101
        $this->assertSame($enum1->getOrdinal(), $enumSet->key());
102
        $this->assertSame($enum1, $enumSet->current());
103
104
        // go to the next element (last)
105
        $this->assertNull($enumSet->next());
106
        $this->assertTrue($enumSet->valid());
107
        $this->assertSame($enum2->getOrdinal(), $enumSet->key());
108
        $this->assertSame($enum2, $enumSet->current());
109
110
        // go to the next element (out of range)
111
        $this->assertNull($enumSet->next());
112
        $this->assertFalse($enumSet->valid());
113
        $this->assertNull($enumSet->current());
114
115
        // rewind will set the iterator position back to 0
116
        $enumSet->rewind();
117
        $this->assertTrue($enumSet->valid());
118
        $this->assertSame(0, $enumSet->key());
119
        $this->assertSame($enum1, $enumSet->current());
120
    }
121
122
    public function testIterateAndDetach()
123
    {
124
        $enumSet = new EnumSet('MabeEnumTest\TestAsset\EnumInheritance');
125
126
        $enum1 = EnumInheritance::ONE();
127
        $enum2 = EnumInheritance::TWO();
128
        $enum3 = EnumInheritance::INHERITANCE();
129
130
        // attach
131
        $enumSet->attach($enum1);
132
        $enumSet->attach($enum2);
133
        $enumSet->attach($enum3);
134
135
        // go to the next entry
136
        $enumSet->next();
137
        $this->assertSame($enum2, $enumSet->current());
138
139
        // detach current entry
140
        $enumSet->detach($enumSet->current());
141
        $this->assertFalse($enumSet->valid());
142
        $this->assertNull($enumSet->current());
143
        $this->assertSame($enum2->getOrdinal(), $enumSet->key());
144
145
        // go to the next entry should be the last entry
146
        $enumSet->next();
147
        $this->assertSame($enum3, $enumSet->current());
148
149
        // detech the last entry
150
        $enumSet->detach($enumSet->current());
151
        $this->assertFalse($enumSet->valid());
152
        $this->assertNull($enumSet->current());
153
        $this->assertSame($enum3->getOrdinal(), $enumSet->key());
154
    }
155
156
    public function testConstructThrowsInvalidArgumentExceptionIfEnumClassDoesNotExtendBaseEnum()
157
    {
158
        $this->setExpectedException('InvalidArgumentException');
159
        new EnumSet('stdClass');
160
    }
161
162
    public function testInitEnumThrowsInvalidArgumentExceptionOnInvalidEnum()
163
    {
164
        $enumSet = new EnumSet('MabeEnumTest\TestAsset\EnumBasic');
165
        $this->setExpectedException('InvalidArgumentException');
166
        $this->assertFalse($enumSet->contains(EnumInheritance::INHERITANCE()));
167
    }
168
169
    public function testIterateOutOfRangeIfLastOrdinalEnumIsSet()
170
    {
171
        $enumSet = new EnumSet('MabeEnumTest\TestAsset\EnumBasic');
172
        $enum    = EnumBasic::byOrdinal(count(EnumBasic::getConstants()) - 1);
173
174
        $enumSet->attach($enum);
175
        $enumSet->rewind();
176
        $this->assertSame($enum, $enumSet->current());
177
178
        // go to the next entry results in out of range
179
        $enumSet->next();
180
        $this->assertFalse($enumSet->valid());
181
        $this->assertSame($enum->getOrdinal() + 1, $enumSet->key());
182
183
        // go more over doesn't change iterator position
184
        $enumSet->next();
185
        $this->assertFalse($enumSet->valid());
186
        $this->assertSame($enum->getOrdinal() + 1, $enumSet->key());
187
    }
188
189 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...
190
    {
191
        $enumSet = new EnumSet('MabeEnumTest\TestAsset\EnumBasic');
192
193
        $enumSet->attach(EnumBasic::TWO);
194
        $enumSet->rewind();
195
        $this->assertGreaterThan(0, $enumSet->key());
196
197
        $enumSet->detach(EnumBasic::TWO);
198
        $enumSet->rewind();
199
        $this->assertSame(0, $enumSet->key());
200
    }
201
202 View Code Duplication
    public function test32EnumerationsSet()
203
    {
204
        $enumSet = new EnumSet('MabeEnumTest\TestAsset\Enum32');
205
        foreach (Enum32::getConstants() as $name => $value) {
206
            $this->assertFalse($enumSet->contains($value));
207
            $enumSet->attach($value);
208
            $this->assertTrue($enumSet->contains($value));
209
        }
210
211
        $this->assertSame(32, $enumSet->count());
212
213
        $expectedOrdinal = 0;
214
        foreach ($enumSet as $ordinal => $enum) {
215
            $this->assertSame($expectedOrdinal, $ordinal);
216
            $this->assertSame($expectedOrdinal, $enum->getOrdinal());
217
            $expectedOrdinal++;
218
        }
219
    }
220
221 View Code Duplication
    public function test64EnumerationsSet()
222
    {
223
        $enumSet = new EnumSet('MabeEnumTest\TestAsset\Enum64');
224
        foreach (Enum64::getConstants() as $name => $value) {
225
            $this->assertFalse($enumSet->contains($value));
226
            $enumSet->attach($value);
227
            $this->assertTrue($enumSet->contains($value));
228
        }
229
230
        $this->assertSame(64, $enumSet->count());
231
232
        $expectedOrdinal = 0;
233
        foreach ($enumSet as $ordinal => $enum) {
234
            $this->assertSame($expectedOrdinal, $ordinal);
235
            $this->assertSame($expectedOrdinal, $enum->getOrdinal());
236
            $expectedOrdinal++;
237
        }
238
    }
239
240
    public function test65EnumerationsSet()
241
    {
242
        $enum = new EnumSet('MabeEnumTest\TestAsset\Enum65');
243
244
        $this->assertNull($enum->attach(Enum65::byOrdinal(64)));
245
        $enum->next();
246
        $this->assertTrue($enum->valid());
247
    }
248
249 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...
250
    {
251
        $enumSet = new EnumSet('MabeEnumTest\TestAsset\Enum65');
252
        
253
        $enum1 = Enum65::ONE;
254
        $enum2 = Enum65::TWO;
255
        $enum3 = Enum65::SIXTYFIVE;
256
        $enum4 = Enum65::SIXTYFOUR;
257
258
        $this->assertNull($enumSet->attach($enum1));
259
        $this->assertSame("\x01\x00\x00\x00\x00\x00\x00\x00\x00", $enumSet->getBinaryBitsetLe());
260
        $this->assertTrue($enumSet->contains($enum1));
261
262
        $this->assertNull($enumSet->attach($enum2));
263
        $this->assertSame("\x03\x00\x00\x00\x00\x00\x00\x00\x00", $enumSet->getBinaryBitsetLe());
264
        $this->assertTrue($enumSet->contains($enum2));
265
266
        $this->assertNull($enumSet->attach($enum3));
267
        $this->assertSame("\x03\x00\x00\x00\x00\x00\x00\x00\x01", $enumSet->getBinaryBitsetLe());
268
        $this->assertTrue($enumSet->contains($enum3));
269
270
        $this->assertNull($enumSet->attach($enum4));
271
        $this->assertSame("\x03\x00\x00\x00\x00\x00\x00\x80\x01", $enumSet->getBinaryBitsetLe());
272
        $this->assertTrue($enumSet->contains($enum4));
273
        
274
        $this->assertSame(4, $enumSet->count());
275
276
        $this->assertNull($enumSet->detach($enum2));
277
        $this->assertSame("\x01\x00\x00\x00\x00\x00\x00\x80\x01", $enumSet->getBinaryBitsetLe());
278
        $this->assertFalse($enumSet->contains($enum2));
279
        
280
        $this->assertSame(3, $enumSet->count());
281
    }
282
283 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...
284
    {
285
        $enumSet = new EnumSet('MabeEnumTest\TestAsset\Enum65');
286
        
287
        $enum1 = Enum65::ONE;
288
        $enum2 = Enum65::TWO;
289
        $enum3 = Enum65::SIXTYFIVE;
290
        $enum4 = Enum65::SIXTYFOUR;
291
292
        $this->assertNull($enumSet->attach($enum1));
293
        $this->assertSame("\x00\x00\x00\x00\x00\x00\x00\x00\x01", $enumSet->getBinaryBitsetBe());
294
        $this->assertTrue($enumSet->contains($enum1));
295
296
        $this->assertNull($enumSet->attach($enum2));
297
        $this->assertSame("\x00\x00\x00\x00\x00\x00\x00\x00\x03", $enumSet->getBinaryBitsetBe());
298
        $this->assertTrue($enumSet->contains($enum2));
299
300
        $this->assertNull($enumSet->attach($enum3));
301
        $this->assertSame("\x01\x00\x00\x00\x00\x00\x00\x00\x03", $enumSet->getBinaryBitsetBe());
302
        $this->assertTrue($enumSet->contains($enum3));
303
304
        $this->assertNull($enumSet->attach($enum4));
305
        $this->assertSame("\x01\x80\x00\x00\x00\x00\x00\x00\x03", $enumSet->getBinaryBitsetBe());
306
        $this->assertTrue($enumSet->contains($enum4));
307
        
308
        $this->assertSame(4, $enumSet->count());
309
310
        $this->assertNull($enumSet->detach($enum2));
311
        $this->assertSame("\x01\x80\x00\x00\x00\x00\x00\x00\x01", $enumSet->getBinaryBitsetBe());
312
        $this->assertFalse($enumSet->contains($enum2));
313
        
314
        $this->assertSame(3, $enumSet->count());
315
    }
316
317
    /**
318
     * @deprecated
319
     */
320 View Code Duplication
    public function testGetBitset()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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