@@ -89,6 +89,26 @@ public function testConstuctorNonStrictValue()
89
89
$ this ->assertSame (1 , $ enum ->getOrdinal ());
90
90
}
91
91
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
+
92
112
public function testInstantiateUsingMagicMethod ()
93
113
{
94
114
if (version_compare (PHP_VERSION , '5.3 ' , '< ' )) {
@@ -99,4 +119,14 @@ public function testInstantiateUsingMagicMethod()
99
119
$ this ->assertInstanceOf ('MabeEnumTest_TestAsset_EnumInheritance ' , $ enum );
100
120
$ this ->assertSame (MabeEnumTest_TestAsset_EnumInheritance::ONE , $ enum ->getValue ());
101
121
}
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
+ }
102
132
}
0 commit comments