Skip to content

Commit 51821ea

Browse files
committed
More tests and better code coverage
1 parent 60a7795 commit 51821ea

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/MabeEnumTest/EnumTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,26 @@ public function testConstuctorNonStrictValue()
8989
$this->assertSame(1, $enum->getOrdinal());
9090
}
9191

92+
public function testCallingGetOrdinalTwoTimesWillResultTheSameValue()
93+
{
94+
$enum = new MabeEnumTest_TestAsset_EnumWithoutDefaultValue(MabeEnumTest_TestAsset_EnumWithoutDefaultValue::TWO);
95+
$this->assertSame(1, $enum->getOrdinal());
96+
$this->assertSame(1, $enum->getOrdinal());
97+
}
98+
99+
public function testGetOrdinalThrowsRuntimeExceptionOnUnknwonValue()
100+
{
101+
$enum = new MabeEnumTest_TestAsset_EnumWithDefaultValue();
102+
103+
// change the protected value property to an unknwon value
104+
$reflectionValue = new ReflectionProperty($enum, 'value');
105+
$reflectionValue->setAccessible(true);
106+
$reflectionValue->setValue($enum, 'unknwonValue');
107+
108+
$this->setExpectedException('RuntimeException');
109+
$enum->getOrdinal();
110+
}
111+
92112
public function testInstantiateUsingMagicMethod()
93113
{
94114
if (version_compare(PHP_VERSION, '5.3', '<')) {
@@ -99,4 +119,14 @@ public function testInstantiateUsingMagicMethod()
99119
$this->assertInstanceOf('MabeEnumTest_TestAsset_EnumInheritance', $enum);
100120
$this->assertSame(MabeEnumTest_TestAsset_EnumInheritance::ONE, $enum->getValue());
101121
}
122+
123+
public function testInstantiateUsingMagicMethodThrowsBadMethodCallException()
124+
{
125+
if (version_compare(PHP_VERSION, '5.3', '<')) {
126+
$this->markTestSkipped("Instantiating using magic method doesn't work for PHP < 5.3");
127+
}
128+
129+
$this->setExpectedException('BadMethodCallException');
130+
MabeEnumTest_TestAsset_EnumInheritance::UNKNOWN();
131+
}
102132
}

0 commit comments

Comments
 (0)