Skip to content

Commit

Permalink
added test for #91 (fails currently) + PHPUnit 6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-mabe committed Sep 28, 2017
1 parent 5544b89 commit e0a3f19
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 35 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"php": "PHP>=5.4 will be required for using trait EnumSerializableTrait"
},
"require-dev": {
"phpunit/phpunit": "^5.0",
"phpunit/phpunit": "^5.7 || ^6.0",
"phpbench/phpbench": "@dev",

"lstrojny/functional-php": "HHVM: variadic params with type constraints are not supported in non-Hack",
Expand Down
16 changes: 13 additions & 3 deletions tests/MabeEnumTest/EnumMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
use MabeEnum\EnumMap;
use MabeEnumTest\TestAsset\EnumBasic;
use MabeEnumTest\TestAsset\EnumInheritance;
use PHPUnit_Framework_TestCase as TestCase;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use Serializable;

/**
* Unit tests for the class MabeEnum\EnumMap
Expand Down Expand Up @@ -159,15 +160,15 @@ public function testArrayAccessWithValues()

public function testConstructThrowsInvalidArgumentExceptionIfEnumClassDoesNotExtendBaseEnum()
{
$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
new EnumMap('stdClass');
}

public function testInitEnumThrowsInvalidArgumentExceptionOnInvalidEnumGiven()
{
$enumMap = new EnumMap(EnumBasic::class);

$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$enumMap->offsetSet(EnumInheritance::INHERITANCE(), 'test');
}

Expand All @@ -181,4 +182,13 @@ public function testContainsAndOffsetExistsReturnsFalseOnInvalidEnum()
$this->assertFalse(isset($enumMap[EnumInheritance::INHERITANCE()]));
$this->assertFalse(isset($enumMap[EnumInheritance::INHERITANCE]));
}

public function testSerializable()
{
$enumMap = new EnumMap(EnumBasic::class);
if ($enumMap instanceof Serializable) {
$enumMap->offsetSet(EnumBasic::ONE, 'one');
serialize($enumMap);
}
}
}
8 changes: 4 additions & 4 deletions tests/MabeEnumTest/EnumSerializableTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use LogicException;
use MabeEnum\Enum;
use MabeEnumTest\TestAsset\SerializableEnum;
use PHPUnit_Framework_TestCase as TestCase;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use RuntimeException;

Expand Down Expand Up @@ -48,19 +48,19 @@ public function testUnserializeFirstWillHoldTheSameInstance()

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

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

public function testUnserializeThrowsLogicExceptionOnChangingValue()
{
$this->setExpectedException(LogicException::class);
$this->expectException(LogicException::class);
$enum = SerializableEnum::get(SerializableEnum::INT);
$enum->unserialize(serialize(SerializableEnum::STR));
}
Expand Down
30 changes: 15 additions & 15 deletions tests/MabeEnumTest/EnumSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use MabeEnumTest\TestAsset\Enum64;
use MabeEnumTest\TestAsset\Enum65;
use MabeEnumTest\TestAsset\Enum66;
use PHPUnit_Framework_TestCase as TestCase;
use PHPUnit\Framework\TestCase;

/**
* Unit tests for the class MabeEnum\EnumSet
Expand Down Expand Up @@ -157,14 +157,14 @@ public function testIterateAndDetach()

public function testConstructThrowsInvalidArgumentExceptionIfEnumClassDoesNotExtendBaseEnum()
{
$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
new EnumSet(self::class);
}

public function testInitEnumThrowsInvalidArgumentExceptionOnInvalidEnum()
{
$enumSet = new EnumSet(EnumBasic::class);
$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$this->assertFalse($enumSet->contains(EnumInheritance::INHERITANCE()));
}

Expand Down Expand Up @@ -396,15 +396,15 @@ public function testSetBinaryBitsetLeBinOutOfRangeBitsOfExtendedBytes1()
{
$enumSet = new EnumSet(Enum65::class);

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

public function testSetBinaryBitsetLeBinOutOfRangeBitsOfExtendedBytes2()
{
$enumSet = new EnumSet(Enum65::class);

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

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

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

public function testSetBinaryBitsetLeBinArgumentExceptionIfNotString()
{
$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);

$enum = new EnumSet(Enum65::class);
$enum->setBinaryBitsetLe(0);
Expand Down Expand Up @@ -450,15 +450,15 @@ public function testSetBinaryBitsetLeIntOutOfRangeBitsOfExtendedBytes1()
{
$enumSet = new EnumSet(EnumBasic::class);

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

public function testSetBinaryBitsetLeIntOutOfRangeBitsOfExtendedBytes2()
{
$enumSet = new EnumSet(EnumBasic::class);

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

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

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

Expand All @@ -488,7 +488,7 @@ public function testSetBinaryBitsetBe()

public function testSetBinaryBitsetBeArgumentExceptionIfNotString()
{
$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);

$enum = new EnumSet(Enum65::class);
$enum->setBinaryBitsetBe(0);
Expand Down Expand Up @@ -805,7 +805,7 @@ public function testUnionThrowsInvalidArgumentException()
$set1 = new EnumSet(EnumBasic::class);
$set2 = new EnumSet(Enum32::class);

$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$set1->union($set2);
}

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

$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$set1->intersect($set2);
}

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

$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$set1->diff($set2);
}

Expand Down Expand Up @@ -883,7 +883,7 @@ public function testSymDiffThrowsInvalidArgumentException()
$set1 = new EnumSet(EnumBasic::class);
$set2 = new EnumSet(Enum32::class);

$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$set1->symDiff($set2);
}
}
24 changes: 12 additions & 12 deletions tests/MabeEnumTest/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use MabeEnumTest\TestAsset\ConstVisibilityEnum;
use MabeEnumTest\TestAsset\ConstVisibilityEnumExtended;
use MabeEnumTest\TestAsset\SerializableEnum;
use PHPUnit_Framework_TestCase as TestCase;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

/**
Expand Down Expand Up @@ -93,19 +93,19 @@ public function testGetWithStrictValue()

public function testGetWithNonStrictValueThrowsInvalidArgumentException()
{
$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
EnumBasic::get((string)EnumBasic::TWO);
}

public function testGetWithInvalidValueThrowsInvalidArgumentException()
{
$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
EnumBasic::get('unknown');
}

public function testGetWithInvalidTypeOfValueThrowsInvalidArgumentException()
{
$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
EnumBasic::get(array());
}

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

$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
EnumBasic::get($enum);
}

Expand Down Expand Up @@ -250,7 +250,7 @@ public function testInstantiateUsingOrdinalNumber()

public function testInstantiateUsingInvalidOrdinalNumberThrowsInvalidArgumentException()
{
$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
EnumInheritance::byOrdinal(17);
}

Expand All @@ -263,7 +263,7 @@ public function testInstantiateByName()

public function testInstantiateByUnknownNameThrowsInvalidArgumentException()
{
$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
EnumInheritance::byName('UNKNOWN');
}

Expand All @@ -276,13 +276,13 @@ public function testInstantiateUsingMagicMethod()

public function testAmbiguousConstantsThrowsLogicException()
{
$this->setExpectedException(LogicException::class);
$this->expectException(LogicException::class);
EnumAmbiguous::get('unknown');
}

public function testExtendedAmbiguousCanstantsThrowsLogicException()
{
$this->setExpectedException(LogicException::class);
$this->expectException(LogicException::class);
EnumExtendedAmbiguous::get('unknown');
}

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

$reflectionMethod->setAccessible(true);
$this->setExpectedException(LogicException::class);
$this->expectException(LogicException::class);
$reflectionMethod->invoke($enum);
}

public function testNotSerializable()
{
$enum = EnumBasic::ONE();

$this->setExpectedException(LogicException::class);
$this->expectException(LogicException::class);
serialize($enum);
}

public function testNotUnserializable()
{
$this->setExpectedException(LogicException::class);
$this->expectException(LogicException::class);
unserialize('O:' . strlen(EnumBasic::class) . ':"' . EnumBasic::class . '":0:{}');
}

Expand Down

0 comments on commit e0a3f19

Please sign in to comment.