File tree Expand file tree Collapse file tree 2 files changed +20
-17
lines changed Expand file tree Collapse file tree 2 files changed +20
-17
lines changed Original file line number Diff line number Diff line change 1212 * Create an enum by implementing this class and adding class constants.
1313 *
1414 * @author Matthieu Napoli <matthieu@mnapoli.fr>
15- * @author Daniel Costa <danielcosta@gmail.com
15+ * @author Daniel Costa <danielcosta@gmail.com>
16+ * @author Mirosław Filip <mirfilip@gmail.com>
1617 */
1718abstract class Enum
1819{
@@ -22,7 +23,7 @@ abstract class Enum
2223 * @var mixed
2324 */
2425 protected $ value ;
25-
26+
2627 /**
2728 * Store existing constants in a static cache per object.
2829 *
Original file line number Diff line number Diff line change 88
99/**
1010 * @author Matthieu Napoli <matthieu@mnapoli.fr>
11- * @author Daniel Costa <danielcosta@gmail.com
11+ * @author Daniel Costa <danielcosta@gmail.com>
12+ * @author Mirosław Filip <mirfilip@gmail.com>
1213 */
1314class EnumTest extends \PHPUnit_Framework_TestCase
1415{
@@ -38,27 +39,28 @@ public function testGetKey()
3839 }
3940
4041 /**
41- * @expectedException \UnexpectedValueException
42+ * @dataProvider invalidValueProvider
4243 */
43- public function testInvalidValueString ( )
44+ public function testCreatingEnumWithInvalidValue ( $ value )
4445 {
45- new EnumFixture ("test " );
46- }
46+ $ this ->setExpectedException (
47+ '\UnexpectedValueException ' ,
48+ 'Value \'' . $ value . '\' is not part of the enum MyCLabs\Tests\Enum\EnumFixture '
49+ );
4750
48- /**
49- * @expectedException \UnexpectedValueException
50- */
51- public function testInvalidValueInt ()
52- {
53- new EnumFixture (1234 );
51+ new EnumFixture ($ value );
5452 }
5553
5654 /**
57- * @expectedException \UnexpectedValueException
55+ * Contains values not existing in EnumFixture
56+ * @return array
5857 */
59- public function testInvalidValueEmpty ()
60- {
61- new EnumFixture (null );
58+ public function invalidValueProvider () {
59+ return [
60+ "string " => ['test ' ],
61+ "int " => [1234 ],
62+ "null " => [null ],
63+ ];
6264 }
6365
6466 /**
You can’t perform that action at this time.
0 commit comments