7
7
8
8
class EnumTest extends \PHPUnit_Framework_TestCase
9
9
{
10
- public function goodKeyProvider ()
10
+ /**
11
+ * @dataProvider dataCallStaticsWorks
12
+ * @param string $name
13
+ * @param mixed $expectedValue
14
+ */
15
+ public function testCallStaticsWorks ($ name , $ expectedValue )
11
16
{
12
- return array (array ("MY_TRUE " , 1 ), array ("MY_FALSE " , 2 ));
17
+ if ($ expectedValue instanceof \Exception) {
18
+ $ this ->setExpectedException (get_class ($ expectedValue ));
19
+ }
20
+
21
+ $ this ->assertSame ($ expectedValue , MyBoolean::__callStatic ($ name , [])->getValue ());
13
22
}
14
23
15
- public function wrongKeyProvider ()
24
+ public function dataCallStaticsWorks ()
16
25
{
17
- return array (array ("MY_NULL " ), array ("MY_VOID " ));
26
+ return [
27
+ ["MY_TRUE " , 1 ],
28
+ ["MY_FALSE " , 2 ],
29
+ ["MY_NULL " , new OutOfRangeException ()]
30
+ ];
18
31
}
19
32
20
33
/**
21
- * @covers EnumMock::__callStatic
22
- * @dataProvider goodKeyProvider
23
- *
24
- * @param string $name
34
+ * @dataProvider dataFindByValueWorks
25
35
* @param mixed $value
36
+ * @param mixed $expectedEnum
26
37
*/
27
- public function testMagicConstruction_GoodKey ( $ name , $ value )
38
+ public function testFindByValueWorks ( $ value , $ expectedEnum )
28
39
{
29
- /** @var MyBoolean $enum */
30
- $ enum = MyBoolean::$ name ();
40
+ if ($ expectedEnum instanceof \Exception) {
41
+ $ this ->setExpectedException (get_class ($ expectedEnum ));
42
+ }
31
43
32
- $ this ->assertInstanceOf (MyBoolean::getClass (), $ enum );
33
- $ this ->assertSame ($ name , $ enum ->getName ());
34
- $ this ->assertSame ($ value , $ enum ->getValue ());
44
+ $ this ->assertSame ($ expectedEnum , MyBoolean::findByValue ($ value ));
35
45
}
36
46
37
- /**
38
- * @covers EnumMock::__callStatic
39
- * @dataProvider wrongKeyProvider
40
- *
41
- * @param string $name
42
- */
43
- public function testMagicConstruction_WrongKey ($ name )
47
+ public function dataFindByValueWorks ()
44
48
{
45
- $ this ->setExpectedException (OutOfRangeException::class);
46
-
47
- MyBoolean::$ name ();
49
+ return [
50
+ [1 , MyBoolean::MY_TRUE ()],
51
+ [2 , MyBoolean::MY_FALSE ()],
52
+ [3 , new OutOfRangeException ()]
53
+ ];
48
54
}
49
55
50
- /**
51
- * @covers EnumMock::__callStatic
52
- */
53
- public function testComparable ()
56
+ public function testComparableWorks ()
54
57
{
55
58
$ this ->assertSame (MyBoolean::MY_TRUE (), MyBoolean::MY_TRUE ());
56
59
$ this ->assertNotSame (MyBoolean::MY_TRUE (), MyBoolean::MY_FALSE ());
@@ -59,41 +62,11 @@ public function testComparable()
59
62
$ this ->assertFalse (MyBoolean::MY_TRUE () == MyBoolean::MY_FALSE ());
60
63
}
61
64
62
- /**
63
- * @covers EnumMock::getMembers
64
- * @runInSeparateProcess
65
- */
66
- public function testGetMembers ()
67
- {
68
- $ members = MyBoolean::getMembers ();
69
-
70
- $ this ->assertInternalType ("array " , $ members );
71
- $ this ->assertCount (2 , $ members );
72
- $ this ->assertArrayHasKey ("MY_TRUE " , $ members );
73
- $ this ->assertEquals (1 , $ members ["MY_TRUE " ]);
74
- $ this ->assertArrayHasKey ("MY_FALSE " , $ members );
75
- $ this ->assertEquals (2 , $ members ["MY_FALSE " ]);
76
- }
77
-
78
- /**
79
- * @dataProvider dataFindByValue
80
- * @param mixed $value
81
- * @param mixed $expected
82
- */
83
- public function testFindByValue ($ value , $ expected )
65
+ public function testGetMembersWorks ()
84
66
{
85
- if ($ expected instanceof \Exception) {
86
- $ this ->setExpectedException (get_class ($ expected ));
87
- }
88
- $ this ->assertSame ($ expected , MyBoolean::findByValue ($ value ));
89
- }
90
-
91
- public function dataFindByValue ()
92
- {
93
- return [
94
- [1 , MyBoolean::MY_TRUE ()],
95
- [2 , MyBoolean::MY_FALSE ()],
96
- [3 , new OutOfRangeException ()]
97
- ];
67
+ $ this ->assertEquals ([
68
+ "MY_TRUE " => 1 ,
69
+ "MY_FALSE " => 2
70
+ ], MyBoolean::getMembers ());
98
71
}
99
72
}
0 commit comments