44 * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
55 */
66
7- namespace UnitTest \MyCLabs \Enum \Enum ;
8-
9- use MyCLabs \Enum \Enum ;
7+ namespace MyCLabs \Enum ;
108
119/**
1210 * Enum test
1311 *
12+ * @package MyCLabs\Enum
1413 * @author Matthieu Napoli <matthieu@mnapoli.fr>
1514 */
1615class EnumTest extends \PHPUnit_Framework_TestCase
@@ -30,26 +29,36 @@ public function testGetValue()
3029 $ this ->assertEquals (EnumFixture::NUMBER , $ value ->getValue ());
3130 }
3231
32+ /**
33+ * getKey()
34+ */
35+ public function testGetKey ()
36+ {
37+ $ value = new EnumFixture (EnumFixture::FOO );
38+ $ this ->assertEquals ('FOO ' , $ value ->getKey ());
39+ $ this ->assertNotEquals ('BA ' , $ value ->getKey ());
40+ }
41+
3342 /**
3443 * @expectedException \UnexpectedValueException
3544 */
36- public function testInvalidValue1 ()
45+ public function testInvalidValueString ()
3746 {
3847 new EnumFixture ("test " );
3948 }
4049
4150 /**
4251 * @expectedException \UnexpectedValueException
4352 */
44- public function testInvalidValue2 ()
53+ public function testInvalidValueInt ()
4554 {
4655 new EnumFixture (1234 );
4756 }
4857
4958 /**
5059 * @expectedException \UnexpectedValueException
5160 */
52- public function testInvalidValue3 ()
61+ public function testInvalidValueEmpty ()
5362 {
5463 new EnumFixture (null );
5564 }
@@ -70,11 +79,26 @@ public function testToString()
7079 }
7180
7281 /**
73- * toArray ()
82+ * keys ()
7483 */
75- public function testToArray ()
84+ public function testKeys ()
85+ {
86+ $ values = EnumFixture::keys ();
87+ $ this ->assertInternalType ("array " , $ values );
88+ $ expectedValues = array (
89+ "FOO " ,
90+ "BAR " ,
91+ "NUMBER " ,
92+ );
93+ $ this ->assertEquals ($ expectedValues , $ values );
94+ }
95+
96+ /**
97+ * values()
98+ */
99+ public function testValues ()
76100 {
77- $ values = EnumFixture::toArray ();
101+ $ values = EnumFixture::values ();
78102 $ this ->assertInternalType ("array " , $ values );
79103 $ expectedValues = array (
80104 "FOO " => EnumFixture::FOO ,
@@ -84,6 +108,14 @@ public function testToArray()
84108 $ this ->assertEquals ($ expectedValues , $ values );
85109 }
86110
111+ /**
112+ * toArray()
113+ */
114+ public function testToArray ()
115+ {
116+ $ this ->assertEquals (EnumFixture::values (), EnumFixture::toArray ());
117+ }
118+
87119 /**
88120 * __callStatic()
89121 */
@@ -96,24 +128,38 @@ public function testStaticAccess()
96128
97129 /**
98130 * @expectedException \BadMethodCallException
99- * @expectedExceptionMessage No static method or enum constant 'UNKNOWN' in class UnitTest\MyCLabs\Enum\Enum\EnumFixture
131+ * @expectedExceptionMessage No static method or enum constant 'UNKNOWN' in class
132+ * UnitTest\MyCLabs\Enum\Enum\EnumFixture
100133 */
101134 public function testBadStaticAccess ()
102135 {
103136 EnumFixture::UNKNOWN ();
104137 }
105- }
106138
107- /**
108- * Fixture class
109- *
110- * @method static EnumFixture FOO()
111- * @method static EnumFixture BAR()
112- * @method static EnumFixture NUMBER()
113- */
114- class EnumFixture extends Enum
115- {
116- const FOO = "foo " ;
117- const BAR = "bar " ;
118- const NUMBER = 42 ;
139+ /**
140+ * isValid()
141+ */
142+ public function testIsValid ()
143+ {
144+ $ this ->assertTrue (EnumFixture::isValid ('foo ' ));
145+ $ this ->assertFalse (EnumFixture::isValid ('baz ' ));
146+ }
147+
148+ /**
149+ * ssValidKey()
150+ */
151+ public function testIsValidKey ()
152+ {
153+ $ this ->assertTrue (EnumFixture::isValidKey ('FOO ' ));
154+ $ this ->assertFalse (EnumFixture::isValidKey ('BAZ ' ));
155+ }
156+
157+ /**
158+ * search()
159+ */
160+ public function testSearch ()
161+ {
162+ $ this ->assertEquals ('FOO ' , EnumFixture::search ('foo ' ));
163+ $ this ->assertNotEquals ('FOO ' , EnumFixture::isValidKey ('baz ' ));
164+ }
119165}
0 commit comments