Skip to content
This repository was archived by the owner on Dec 26, 2023. It is now read-only.

Commit 7641dcc

Browse files
author
Petr Knap
committed
Improved tests
1 parent 5179d42 commit 7641dcc

File tree

1 file changed

+36
-63
lines changed

1 file changed

+36
-63
lines changed

tests/Enum/EnumTest.php

Lines changed: 36 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,53 @@
77

88
class EnumTest extends \PHPUnit_Framework_TestCase
99
{
10-
public function goodKeyProvider()
10+
/**
11+
* @dataProvider dataCallStaticsWorks
12+
* @param string $name
13+
* @param mixed $expectedValue
14+
*/
15+
public function testCallStaticsWorks($name, $expectedValue)
1116
{
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());
1322
}
1423

15-
public function wrongKeyProvider()
24+
public function dataCallStaticsWorks()
1625
{
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+
];
1831
}
1932

2033
/**
21-
* @covers EnumMock::__callStatic
22-
* @dataProvider goodKeyProvider
23-
*
24-
* @param string $name
34+
* @dataProvider dataFindByValueWorks
2535
* @param mixed $value
36+
* @param mixed $expectedEnum
2637
*/
27-
public function testMagicConstruction_GoodKey($name, $value)
38+
public function testFindByValueWorks($value, $expectedEnum)
2839
{
29-
/** @var MyBoolean $enum */
30-
$enum = MyBoolean::$name();
40+
if ($expectedEnum instanceof \Exception) {
41+
$this->setExpectedException(get_class($expectedEnum));
42+
}
3143

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));
3545
}
3646

37-
/**
38-
* @covers EnumMock::__callStatic
39-
* @dataProvider wrongKeyProvider
40-
*
41-
* @param string $name
42-
*/
43-
public function testMagicConstruction_WrongKey($name)
47+
public function dataFindByValueWorks()
4448
{
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+
];
4854
}
4955

50-
/**
51-
* @covers EnumMock::__callStatic
52-
*/
53-
public function testComparable()
56+
public function testComparableWorks()
5457
{
5558
$this->assertSame(MyBoolean::MY_TRUE(), MyBoolean::MY_TRUE());
5659
$this->assertNotSame(MyBoolean::MY_TRUE(), MyBoolean::MY_FALSE());
@@ -59,41 +62,11 @@ public function testComparable()
5962
$this->assertFalse(MyBoolean::MY_TRUE() == MyBoolean::MY_FALSE());
6063
}
6164

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()
8466
{
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());
9871
}
9972
}

0 commit comments

Comments
 (0)