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

Commit 0f19e31

Browse files
author
Petr Knap
committed
AbstractEnum 1.0
2 parents b917685 + 6f365e3 commit 0f19e31

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

src/Enum/AbstractEnum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @author Petr Knap <dev@petrknap.cz>
99
* @since 2016-01-23
1010
* @package PetrKnap\Php\Enum
11-
* @version 0.4
11+
* @version 1.0
1212
* @license https://github.com/petrknap/php-enum/blob/master/LICENSE MIT
1313
*/
1414
abstract class AbstractEnum

tests/Enum/EnumTest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
namespace PetrKnap\Php\Enum\Test;
44

55
use PetrKnap\Php\Enum\EnumException;
6-
use PetrKnap\Php\Enum\Test\EnumTest\EnumMock;
6+
use PetrKnap\Php\Enum\Test\EnumTest\MyBoolean;
77

88
class EnumTest extends \PHPUnit_Framework_TestCase
99
{
1010
public function goodKeyProvider()
1111
{
12-
return [["A", "a"], ["B", "b"]];
12+
return [["MY_TRUE", 1], ["MY_FALSE", 2]];
1313
}
1414

1515
public function wrongKeyProvider()
1616
{
17-
return [["C"], ["D"]];
17+
return [["MY_NULL"], ["MY_VOID"]];
1818
}
1919

2020
/**
@@ -26,10 +26,10 @@ public function wrongKeyProvider()
2626
*/
2727
public function testMagicConstruction_GoodKey($name, $value)
2828
{
29-
/** @var EnumMock $enum */
30-
$enum = EnumMock::$name();
29+
/** @var MyBoolean $enum */
30+
$enum = MyBoolean::$name();
3131

32-
$this->assertInstanceOf(EnumMock::getClass(), $enum);
32+
$this->assertInstanceOf(MyBoolean::getClass(), $enum);
3333
$this->assertSame($name, $enum->getName());
3434
$this->assertSame($value, $enum->getValue());
3535
}
@@ -48,19 +48,19 @@ public function testMagicConstruction_WrongKey($name)
4848
EnumException::OUT_OF_RANGE
4949
);
5050

51-
EnumMock::$name();
51+
MyBoolean::$name();
5252
}
5353

5454
/**
5555
* @covers EnumMock::__callStatic
5656
*/
5757
public function testComparable()
5858
{
59-
$this->assertSame(EnumMock::A(), EnumMock::A());
60-
$this->assertNotSame(EnumMock::A(), EnumMock::B());
59+
$this->assertSame(MyBoolean::MY_TRUE(), MyBoolean::MY_TRUE());
60+
$this->assertNotSame(MyBoolean::MY_TRUE(), MyBoolean::MY_FALSE());
6161

62-
$this->assertTrue(EnumMock::A() == EnumMock::A());
63-
$this->assertFalse(EnumMock::A() == EnumMock::B());
62+
$this->assertTrue(MyBoolean::MY_TRUE() == MyBoolean::MY_TRUE());
63+
$this->assertFalse(MyBoolean::MY_TRUE() == MyBoolean::MY_FALSE());
6464
}
6565

6666
/**
@@ -69,13 +69,13 @@ public function testComparable()
6969
*/
7070
public function testGetMembers()
7171
{
72-
$members = EnumMock::getMembers();
72+
$members = MyBoolean::getMembers();
7373

7474
$this->assertInternalType("array", $members);
7575
$this->assertCount(2, $members);
76-
$this->assertArrayHasKey("A", $members);
77-
$this->assertEquals("a", $members["A"]);
78-
$this->assertArrayHasKey("B", $members);
79-
$this->assertEquals("b", $members["B"]);
76+
$this->assertArrayHasKey("MY_TRUE", $members);
77+
$this->assertEquals(1, $members["MY_TRUE"]);
78+
$this->assertArrayHasKey("MY_FALSE", $members);
79+
$this->assertEquals(2, $members["MY_FALSE"]);
8080
}
8181
}

tests/Enum/EnumTest/EnumMock.php renamed to tests/Enum/EnumTest/MyBoolean.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
use PetrKnap\Php\Enum\AbstractEnum;
66

77
/**
8-
* @method static EnumMock A()
9-
* @method static EnumMock B()
8+
* @method static MyBoolean MY_TRUE()
9+
* @method static MyBoolean MY_FALSE()
1010
*/
11-
class EnumMock extends AbstractEnum
11+
class MyBoolean extends AbstractEnum
1212
{
1313
protected function members()
1414
{
1515
return [
16-
"A" => "a",
17-
"B" => "b"
16+
"MY_TRUE" => 1,
17+
"MY_FALSE" => 2
1818
];
1919
}
2020

0 commit comments

Comments
 (0)