Completed
Push — enumset_produce ( 6ef986 )
by Marc
02:00
created

EnumSetTest::testDiff()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 17

Duplication

Lines 22
Ratio 100 %

Importance

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

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
336
        $this->assertTrue($enumSet->contains($enum1));
337
338
        $this->assertNull($enumSet->attach($enum2));
339
        $this->assertSame("\x00\x00\x00\x00\x00\x00\x00\x00\x03", $enumSet->getBitset());
0 ignored issues
show
Deprecated Code introduced by
The method MabeEnum\EnumSet::getBitset() has been deprecated with message: Please use getBinaryBitsetBe() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
340
        $this->assertTrue($enumSet->contains($enum2));
341
342
        $this->assertNull($enumSet->attach($enum3));
343
        $this->assertSame("\x01\x00\x00\x00\x00\x00\x00\x00\x03", $enumSet->getBitset());
0 ignored issues
show
Deprecated Code introduced by
The method MabeEnum\EnumSet::getBitset() has been deprecated with message: Please use getBinaryBitsetBe() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
344
        $this->assertTrue($enumSet->contains($enum3));
345
346
        $this->assertNull($enumSet->attach($enum4));
347
        $this->assertSame("\x01\x80\x00\x00\x00\x00\x00\x00\x03", $enumSet->getBitset());
0 ignored issues
show
Deprecated Code introduced by
The method MabeEnum\EnumSet::getBitset() has been deprecated with message: Please use getBinaryBitsetBe() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
348
        $this->assertTrue($enumSet->contains($enum4));
349
        
350
        $this->assertSame(4, $enumSet->count());
351
352
        $this->assertNull($enumSet->detach($enum2));
353
        $this->assertSame("\x01\x80\x00\x00\x00\x00\x00\x00\x01", $enumSet->getBitset());
0 ignored issues
show
Deprecated Code introduced by
The method MabeEnum\EnumSet::getBitset() has been deprecated with message: Please use getBinaryBitsetBe() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
354
        $this->assertFalse($enumSet->contains($enum2));
355
        
356
        $this->assertSame(3, $enumSet->count());
357
    }
358
359 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...
360
    {
361
        $enumSet = new EnumSet('MabeEnumTest\TestAsset\Enum65');
362
        $enumSet->setBinaryBitsetLe("\x01\x00\x00\x00\x00\x00\x00\x80\x01");
363
364
        $this->assertTrue($enumSet->contains(Enum65::ONE));
365
        $this->assertFalse($enumSet->contains(Enum65::TWO));
366
        $this->assertTrue($enumSet->contains(Enum65::SIXTYFIVE));
367
        $this->assertTrue($enumSet->contains(Enum65::SIXTYFOUR));
368
        $this->assertTrue($enumSet->count() == 3);
369
    }
370
371 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...
372
    {
373
        $enumSet = new EnumSet('MabeEnumTest\TestAsset\Enum65');
374
        $enumSet->setBinaryBitsetBe("\x01\x80\x00\x00\x00\x00\x00\x00\x01");
375
376
        $this->assertTrue($enumSet->contains(Enum65::ONE));
377
        $this->assertFalse($enumSet->contains(Enum65::TWO));
378
        $this->assertTrue($enumSet->contains(Enum65::SIXTYFIVE));
379
        $this->assertTrue($enumSet->contains(Enum65::SIXTYFOUR));
380
        $this->assertTrue($enumSet->count() == 3);
381
    }
382
383
    /**
384
     * @deprecated
385
     */
386 View Code Duplication
    public function testSetBitset()
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...
387
    {
388
        $enumSet = new EnumSet('MabeEnumTest\TestAsset\Enum65');
389
        $enumSet->setBitset("\x01\x80\x00\x00\x00\x00\x00\x00\x01");
0 ignored issues
show
Deprecated Code introduced by
The method MabeEnum\EnumSet::setBitset() has been deprecated with message: Please use setBinaryBitsetBe() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

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