Skip to content

Commit 970ed20

Browse files
committed
Rewrite tests of creating Enum from invalid values - use data provider
1 parent c0bcd73 commit 970ed20

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

src/Enum.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
* Create an enum by implementing this class and adding class constants.
1313
*
1414
* @author Matthieu Napoli <[email protected]>
15-
* @author Daniel Costa <[email protected]
15+
* @author Daniel Costa <[email protected]>
16+
* @author Mirosław Filip <[email protected]>
1617
*/
1718
abstract 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
*

tests/EnumTest.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
/**
1010
* @author Matthieu Napoli <[email protected]>
11-
* @author Daniel Costa <[email protected]
11+
* @author Daniel Costa <[email protected]>
12+
* @author Mirosław Filip <[email protected]>
1213
*/
1314
class 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
/**

0 commit comments

Comments
 (0)