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

Commit e36e37c

Browse files
author
Petr Knap
committed
Added getConstants method
1 parent daa0ecf commit e36e37c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Enum/AbstractEnum.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ protected static function setConstants(array $constants)
9393
self::$constants[get_called_class()] = $constants;
9494
}
9595

96+
/**
97+
* @return mixed[]
98+
*/
99+
public static function getConstants()
100+
{
101+
return self::$constants[get_called_class()];
102+
}
103+
96104
/**
97105
* @param string $constantName
98106
* @return bool

tests/Enum/EnumTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,18 @@ public function testEnumMagicConstruction_WrongKey($name)
4646

4747
EnumMock::$name();
4848
}
49+
50+
/**
51+
* @dataProvider goodKeyProvider
52+
* @param string $name
53+
* @param mixed $value
54+
*/
55+
public function testGetConstants($name, $value)
56+
{
57+
$constants = EnumMock::getConstants();
58+
59+
$this->assertInternalType("array", $constants);
60+
$this->assertArrayHasKey($name, $constants);
61+
$this->assertEquals($value, $constants[$name]);
62+
}
4963
}

0 commit comments

Comments
 (0)