Skip to content

Commit

Permalink
Abstract classes in Enum inheritance hierarchy are skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
paranoiq committed Aug 28, 2021
1 parent bdb88bc commit 9e408ac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Enum/EnumSetMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ final protected static function init(string $class): void
/** @var ReflectionClass<Enum|Set> $parent */
$parent = $ref->getParentClass();
$parentClass = $parent->getName();
if (!in_array($parentClass, [IntEnum::class, StringEnum::class, IntSet::class, StringSet::class], true) && $parent->isAbstract()) {
/** @var ReflectionClass<Enum|Set> $parent */
$parent = $parent->getParentClass();
$parentClass = $parent->getName();
}
$isDescendant = !in_array($parentClass, $rootClasses, true);

$parentValues = [];
Expand Down
22 changes: 19 additions & 3 deletions tests/src/Enum/Enum.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ class E extends IntEnum

}

// skip abstract
abstract class F extends IntEnum
{

}

class G extends F
{

public const ONE = 1;
public const TWO = 2;

}

$aOne = A::get(1);
$aOne2 = A::get(1);
$aTwo = A::get(2);
Expand All @@ -63,12 +77,14 @@ $abOne = AB::get(1);
$abcOne = ABC::get(1);
$abcTwo = ABC::get(2);
$abdOne = ABD::get(1);
$fOne = E::get(1);
$eOne = E::get(1);
$gOne = G::get(1);


get:
Assert::type($aOne, A::class);
Assert::equal($aOne, $aOne2);
Assert::equal($gOne, G::get(1));


getValue:
Expand All @@ -80,8 +96,8 @@ Assert::same($aOne->getConstantName(), 'ONE');


equals:
Assert::exception(static function () use ($aOne, $fOne): void {
$aOne->equals($fOne);
Assert::exception(static function () use ($aOne, $eOne): void {
$aOne->equals($eOne);
}, InvalidTypeException::class);
Assert::false($aOne->equals($aTwo));
Assert::true($aOne->equals($aOne2));
Expand Down

0 comments on commit 9e408ac

Please sign in to comment.