Skip to content

Commit e0a3f19

Browse files
committed
added test for #91 (fails currently) + PHPUnit 6 support
1 parent 5544b89 commit e0a3f19

File tree

5 files changed

+45
-35
lines changed

5 files changed

+45
-35
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"php": "PHP>=5.4 will be required for using trait EnumSerializableTrait"
2929
},
3030
"require-dev": {
31-
"phpunit/phpunit": "^5.0",
31+
"phpunit/phpunit": "^5.7 || ^6.0",
3232
"phpbench/phpbench": "@dev",
3333

3434
"lstrojny/functional-php": "HHVM: variadic params with type constraints are not supported in non-Hack",

tests/MabeEnumTest/EnumMapTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
use MabeEnum\EnumMap;
77
use MabeEnumTest\TestAsset\EnumBasic;
88
use MabeEnumTest\TestAsset\EnumInheritance;
9-
use PHPUnit_Framework_TestCase as TestCase;
9+
use PHPUnit\Framework\TestCase;
1010
use ReflectionClass;
11+
use Serializable;
1112

1213
/**
1314
* Unit tests for the class MabeEnum\EnumMap
@@ -159,15 +160,15 @@ public function testArrayAccessWithValues()
159160

160161
public function testConstructThrowsInvalidArgumentExceptionIfEnumClassDoesNotExtendBaseEnum()
161162
{
162-
$this->setExpectedException(InvalidArgumentException::class);
163+
$this->expectException(InvalidArgumentException::class);
163164
new EnumMap('stdClass');
164165
}
165166

166167
public function testInitEnumThrowsInvalidArgumentExceptionOnInvalidEnumGiven()
167168
{
168169
$enumMap = new EnumMap(EnumBasic::class);
169170

170-
$this->setExpectedException(InvalidArgumentException::class);
171+
$this->expectException(InvalidArgumentException::class);
171172
$enumMap->offsetSet(EnumInheritance::INHERITANCE(), 'test');
172173
}
173174

@@ -181,4 +182,13 @@ public function testContainsAndOffsetExistsReturnsFalseOnInvalidEnum()
181182
$this->assertFalse(isset($enumMap[EnumInheritance::INHERITANCE()]));
182183
$this->assertFalse(isset($enumMap[EnumInheritance::INHERITANCE]));
183184
}
185+
186+
public function testSerializable()
187+
{
188+
$enumMap = new EnumMap(EnumBasic::class);
189+
if ($enumMap instanceof Serializable) {
190+
$enumMap->offsetSet(EnumBasic::ONE, 'one');
191+
serialize($enumMap);
192+
}
193+
}
184194
}

tests/MabeEnumTest/EnumSerializableTraitTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use LogicException;
66
use MabeEnum\Enum;
77
use MabeEnumTest\TestAsset\SerializableEnum;
8-
use PHPUnit_Framework_TestCase as TestCase;
8+
use PHPUnit\Framework\TestCase;
99
use ReflectionClass;
1010
use RuntimeException;
1111

@@ -48,19 +48,19 @@ public function testUnserializeFirstWillHoldTheSameInstance()
4848

4949
public function testUnserializeThrowsRuntimeExceptionOnUnknownValue()
5050
{
51-
$this->setExpectedException(RuntimeException::class);
51+
$this->expectException(RuntimeException::class);
5252
unserialize('C:' . strlen(SerializableEnum::class) . ':"' . SerializableEnum::class . '":11:{s:4:"test";}');
5353
}
5454

5555
public function testUnserializeThrowsRuntimeExceptionOnInvalidValue()
5656
{
57-
$this->setExpectedException(RuntimeException::class);
57+
$this->expectException(RuntimeException::class);
5858
unserialize('C:' . strlen(SerializableEnum::class) . ':"' . SerializableEnum::class . '":19:{O:8:"stdClass":0:{}}');
5959
}
6060

6161
public function testUnserializeThrowsLogicExceptionOnChangingValue()
6262
{
63-
$this->setExpectedException(LogicException::class);
63+
$this->expectException(LogicException::class);
6464
$enum = SerializableEnum::get(SerializableEnum::INT);
6565
$enum->unserialize(serialize(SerializableEnum::STR));
6666
}

tests/MabeEnumTest/EnumSetTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use MabeEnumTest\TestAsset\Enum64;
1313
use MabeEnumTest\TestAsset\Enum65;
1414
use MabeEnumTest\TestAsset\Enum66;
15-
use PHPUnit_Framework_TestCase as TestCase;
15+
use PHPUnit\Framework\TestCase;
1616

1717
/**
1818
* Unit tests for the class MabeEnum\EnumSet
@@ -157,14 +157,14 @@ public function testIterateAndDetach()
157157

158158
public function testConstructThrowsInvalidArgumentExceptionIfEnumClassDoesNotExtendBaseEnum()
159159
{
160-
$this->setExpectedException(InvalidArgumentException::class);
160+
$this->expectException(InvalidArgumentException::class);
161161
new EnumSet(self::class);
162162
}
163163

164164
public function testInitEnumThrowsInvalidArgumentExceptionOnInvalidEnum()
165165
{
166166
$enumSet = new EnumSet(EnumBasic::class);
167-
$this->setExpectedException(InvalidArgumentException::class);
167+
$this->expectException(InvalidArgumentException::class);
168168
$this->assertFalse($enumSet->contains(EnumInheritance::INHERITANCE()));
169169
}
170170

@@ -396,15 +396,15 @@ public function testSetBinaryBitsetLeBinOutOfRangeBitsOfExtendedBytes1()
396396
{
397397
$enumSet = new EnumSet(Enum65::class);
398398

399-
$this->setExpectedException(InvalidArgumentException::class, 'Out-Of-Range');
399+
$this->expectException(InvalidArgumentException::class, 'Out-Of-Range');
400400
$enumSet->setBinaryBitsetLe("\xff\xff\xff\xff\xff\xff\xff\xff\x00\x02");
401401
}
402402

403403
public function testSetBinaryBitsetLeBinOutOfRangeBitsOfExtendedBytes2()
404404
{
405405
$enumSet = new EnumSet(Enum65::class);
406406

407-
$this->setExpectedException(InvalidArgumentException::class, 'Out-Of-Range');
407+
$this->expectException(InvalidArgumentException::class, 'Out-Of-Range');
408408
$enumSet->setBinaryBitsetLe("\xff\xff\xff\xff\xff\xff\xff\xff\x02");
409409
}
410410

@@ -416,13 +416,13 @@ public function testSetBinaryBitsetLeBinOutOfRangeBitsOfLastValidByte()
416416
$bitset = $enumSet->getBinaryBitsetLe();
417417
$newBitset = substr($bitset, 0, -1) . "\x02";
418418

419-
$this->setExpectedException(InvalidArgumentException::class, 'Out-Of-Range');
419+
$this->expectException(InvalidArgumentException::class, 'Out-Of-Range');
420420
$enumSet->setBinaryBitsetLe($newBitset);
421421
}
422422

423423
public function testSetBinaryBitsetLeBinArgumentExceptionIfNotString()
424424
{
425-
$this->setExpectedException(InvalidArgumentException::class);
425+
$this->expectException(InvalidArgumentException::class);
426426

427427
$enum = new EnumSet(Enum65::class);
428428
$enum->setBinaryBitsetLe(0);
@@ -450,15 +450,15 @@ public function testSetBinaryBitsetLeIntOutOfRangeBitsOfExtendedBytes1()
450450
{
451451
$enumSet = new EnumSet(EnumBasic::class);
452452

453-
$this->setExpectedException(InvalidArgumentException::class, 'Out-Of-Range');
453+
$this->expectException(InvalidArgumentException::class, 'Out-Of-Range');
454454
$enumSet->setBinaryBitsetLe("\x0A\xFF\x01");
455455
}
456456

457457
public function testSetBinaryBitsetLeIntOutOfRangeBitsOfExtendedBytes2()
458458
{
459459
$enumSet = new EnumSet(EnumBasic::class);
460460

461-
$this->setExpectedException(InvalidArgumentException::class, 'Out-Of-Range');
461+
$this->expectException(InvalidArgumentException::class, 'Out-Of-Range');
462462
$enumSet->setBinaryBitsetLe("\x01\x01\x01\x01\x01\x01\x01\x01\x01");
463463
}
464464

@@ -470,7 +470,7 @@ public function testSetBinaryBitsetLeIntOutOfRangeBitsOfLastValidByte()
470470
$bitset = $enumSet->getBinaryBitsetLe();
471471
$newBitset = substr($bitset, 0, -1) . "\xFF";
472472

473-
$this->setExpectedException(InvalidArgumentException::class, 'Out-Of-Range');
473+
$this->expectException(InvalidArgumentException::class, 'Out-Of-Range');
474474
$enumSet->setBinaryBitsetLe($newBitset);
475475
}
476476

@@ -488,7 +488,7 @@ public function testSetBinaryBitsetBe()
488488

489489
public function testSetBinaryBitsetBeArgumentExceptionIfNotString()
490490
{
491-
$this->setExpectedException(InvalidArgumentException::class);
491+
$this->expectException(InvalidArgumentException::class);
492492

493493
$enum = new EnumSet(Enum65::class);
494494
$enum->setBinaryBitsetBe(0);
@@ -805,7 +805,7 @@ public function testUnionThrowsInvalidArgumentException()
805805
$set1 = new EnumSet(EnumBasic::class);
806806
$set2 = new EnumSet(Enum32::class);
807807

808-
$this->setExpectedException(InvalidArgumentException::class);
808+
$this->expectException(InvalidArgumentException::class);
809809
$set1->union($set2);
810810
}
811811

@@ -830,7 +830,7 @@ public function testIntersectThrowsInvalidArgumentException()
830830
$set1 = new EnumSet(EnumBasic::class);
831831
$set2 = new EnumSet(Enum32::class);
832832

833-
$this->setExpectedException(InvalidArgumentException::class);
833+
$this->expectException(InvalidArgumentException::class);
834834
$set1->intersect($set2);
835835
}
836836

@@ -855,7 +855,7 @@ public function testDiffThrowsInvalidArgumentException()
855855
$set1 = new EnumSet(EnumBasic::class);
856856
$set2 = new EnumSet(Enum32::class);
857857

858-
$this->setExpectedException(InvalidArgumentException::class);
858+
$this->expectException(InvalidArgumentException::class);
859859
$set1->diff($set2);
860860
}
861861

@@ -883,7 +883,7 @@ public function testSymDiffThrowsInvalidArgumentException()
883883
$set1 = new EnumSet(EnumBasic::class);
884884
$set2 = new EnumSet(Enum32::class);
885885

886-
$this->setExpectedException(InvalidArgumentException::class);
886+
$this->expectException(InvalidArgumentException::class);
887887
$set1->symDiff($set2);
888888
}
889889
}

tests/MabeEnumTest/EnumTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use MabeEnumTest\TestAsset\ConstVisibilityEnum;
1313
use MabeEnumTest\TestAsset\ConstVisibilityEnumExtended;
1414
use MabeEnumTest\TestAsset\SerializableEnum;
15-
use PHPUnit_Framework_TestCase as TestCase;
15+
use PHPUnit\Framework\TestCase;
1616
use ReflectionClass;
1717

1818
/**
@@ -93,19 +93,19 @@ public function testGetWithStrictValue()
9393

9494
public function testGetWithNonStrictValueThrowsInvalidArgumentException()
9595
{
96-
$this->setExpectedException(InvalidArgumentException::class);
96+
$this->expectException(InvalidArgumentException::class);
9797
EnumBasic::get((string)EnumBasic::TWO);
9898
}
9999

100100
public function testGetWithInvalidValueThrowsInvalidArgumentException()
101101
{
102-
$this->setExpectedException(InvalidArgumentException::class);
102+
$this->expectException(InvalidArgumentException::class);
103103
EnumBasic::get('unknown');
104104
}
105105

106106
public function testGetWithInvalidTypeOfValueThrowsInvalidArgumentException()
107107
{
108-
$this->setExpectedException(InvalidArgumentException::class);
108+
$this->expectException(InvalidArgumentException::class);
109109
EnumBasic::get(array());
110110
}
111111

@@ -120,7 +120,7 @@ public function testGetByExtendedInstanceOfKnownValue()
120120
{
121121
$enum = EnumInheritance::get(EnumInheritance::ONE);
122122

123-
$this->setExpectedException(InvalidArgumentException::class);
123+
$this->expectException(InvalidArgumentException::class);
124124
EnumBasic::get($enum);
125125
}
126126

@@ -250,7 +250,7 @@ public function testInstantiateUsingOrdinalNumber()
250250

251251
public function testInstantiateUsingInvalidOrdinalNumberThrowsInvalidArgumentException()
252252
{
253-
$this->setExpectedException(InvalidArgumentException::class);
253+
$this->expectException(InvalidArgumentException::class);
254254
EnumInheritance::byOrdinal(17);
255255
}
256256

@@ -263,7 +263,7 @@ public function testInstantiateByName()
263263

264264
public function testInstantiateByUnknownNameThrowsInvalidArgumentException()
265265
{
266-
$this->setExpectedException(InvalidArgumentException::class);
266+
$this->expectException(InvalidArgumentException::class);
267267
EnumInheritance::byName('UNKNOWN');
268268
}
269269

@@ -276,13 +276,13 @@ public function testInstantiateUsingMagicMethod()
276276

277277
public function testAmbiguousConstantsThrowsLogicException()
278278
{
279-
$this->setExpectedException(LogicException::class);
279+
$this->expectException(LogicException::class);
280280
EnumAmbiguous::get('unknown');
281281
}
282282

283283
public function testExtendedAmbiguousCanstantsThrowsLogicException()
284284
{
285-
$this->setExpectedException(LogicException::class);
285+
$this->expectException(LogicException::class);
286286
EnumExtendedAmbiguous::get('unknown');
287287
}
288288

@@ -303,21 +303,21 @@ public function testCloneNotCallableAndThrowsLogicException()
303303
$this->assertTrue($reflectionMethod->isFinal(), 'The method __clone must be final');
304304

305305
$reflectionMethod->setAccessible(true);
306-
$this->setExpectedException(LogicException::class);
306+
$this->expectException(LogicException::class);
307307
$reflectionMethod->invoke($enum);
308308
}
309309

310310
public function testNotSerializable()
311311
{
312312
$enum = EnumBasic::ONE();
313313

314-
$this->setExpectedException(LogicException::class);
314+
$this->expectException(LogicException::class);
315315
serialize($enum);
316316
}
317317

318318
public function testNotUnserializable()
319319
{
320-
$this->setExpectedException(LogicException::class);
320+
$this->expectException(LogicException::class);
321321
unserialize('O:' . strlen(EnumBasic::class) . ':"' . EnumBasic::class . '":0:{}');
322322
}
323323

0 commit comments

Comments
 (0)