Skip to content

Commit 5c76705

Browse files
committed
Mabe\Enum\Cl\enum_exists should except EmulatedUnitEnum
1 parent 29862f4 commit 5c76705

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

src/functions.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ function enum_exists(string $enum, bool $autoload = true) : bool
7070
}
7171

7272
return \class_exists($enum, $autoload) && (
73-
\is_a($enum, __NAMESPACE__ . '\\IntBackedEnum', true)
74-
|| \is_a($enum, __NAMESPACE__ . '\\StringBackedEnum', true)
73+
\is_a($enum, __NAMESPACE__ . '\\EmulatedUnitEnum', true)
74+
|| \is_a($enum, __NAMESPACE__ . '\\EmulatedBackedEnum', true)
7575
);
7676
}
7777
}
78-

src/stubs/BackedEnum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @link http://github.com/marc-mabe/php-enum-cl for the canonical source repository
99
*/
1010
interface BackedEnum extends UnitEnum {
11-
//public string|int $value;
11+
//public readonly string|int $value;
1212

1313
/**
1414
* @param string|int $value

src/stubs/UnitEnum.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* @link http://github.com/marc-mabe/php-enum-cl for the canonical source repository
99
*/
1010
interface UnitEnum {
11-
//public string $name;
12-
11+
//public readonly string $name;
12+
1313
/**
1414
* @return static[]
1515
* @phpstan-return array<int, static>

tests/EnumExistsTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ public function testUnitEnumNative()
1515
static::assertTrue(enum_exists(__FUNCTION__));
1616
}
1717

18+
public function testUnitEnumEmulated()
19+
{
20+
if (PHP_VERSION_ID >= 80100) {
21+
$this->markTestSkipped('This test is for PHP < 8.1 only');
22+
}
23+
24+
eval('final class ' . __FUNCTION__ . ' extends Mabe\Enum\Cl\EmulatedUnitEnum {}');
25+
static::assertTrue(enum_exists(__FUNCTION__));
26+
}
27+
1828
public function testIntBackedEnumEmulated()
1929
{
2030
if (PHP_VERSION_ID >= 80100) {

0 commit comments

Comments
 (0)