4
4
* @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
5
5
*/
6
6
7
- namespace UnitTest \MyCLabs \Enum \Enum ;
8
-
9
- use MyCLabs \Enum \Enum ;
7
+ namespace MyCLabs \Enum ;
10
8
11
9
/**
12
10
* Enum test
13
11
*
12
+ * @package MyCLabs\Enum
14
13
* @author Matthieu Napoli <[email protected] >
15
14
*/
16
15
class EnumTest extends \PHPUnit_Framework_TestCase
@@ -30,26 +29,36 @@ public function testGetValue()
30
29
$ this ->assertEquals (EnumFixture::NUMBER , $ value ->getValue ());
31
30
}
32
31
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
+
33
42
/**
34
43
* @expectedException \UnexpectedValueException
35
44
*/
36
- public function testInvalidValue1 ()
45
+ public function testInvalidValueString ()
37
46
{
38
47
new EnumFixture ("test " );
39
48
}
40
49
41
50
/**
42
51
* @expectedException \UnexpectedValueException
43
52
*/
44
- public function testInvalidValue2 ()
53
+ public function testInvalidValueInt ()
45
54
{
46
55
new EnumFixture (1234 );
47
56
}
48
57
49
58
/**
50
59
* @expectedException \UnexpectedValueException
51
60
*/
52
- public function testInvalidValue3 ()
61
+ public function testInvalidValueEmpty ()
53
62
{
54
63
new EnumFixture (null );
55
64
}
@@ -70,11 +79,26 @@ public function testToString()
70
79
}
71
80
72
81
/**
73
- * toArray ()
82
+ * keys ()
74
83
*/
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 ()
76
100
{
77
- $ values = EnumFixture::toArray ();
101
+ $ values = EnumFixture::values ();
78
102
$ this ->assertInternalType ("array " , $ values );
79
103
$ expectedValues = array (
80
104
"FOO " => EnumFixture::FOO ,
@@ -84,6 +108,14 @@ public function testToArray()
84
108
$ this ->assertEquals ($ expectedValues , $ values );
85
109
}
86
110
111
+ /**
112
+ * toArray()
113
+ */
114
+ public function testToArray ()
115
+ {
116
+ $ this ->assertEquals (EnumFixture::values (), EnumFixture::toArray ());
117
+ }
118
+
87
119
/**
88
120
* __callStatic()
89
121
*/
@@ -96,24 +128,38 @@ public function testStaticAccess()
96
128
97
129
/**
98
130
* @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
100
133
*/
101
134
public function testBadStaticAccess ()
102
135
{
103
136
EnumFixture::UNKNOWN ();
104
137
}
105
- }
106
138
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
+ }
119
165
}
0 commit comments