diff --git a/src/Enum.php b/src/Enum.php index 2999d31..3bce0dc 100644 --- a/src/Enum.php +++ b/src/Enum.php @@ -41,9 +41,7 @@ abstract class Enum implements \JsonSerializable public function __construct($value) { if ($value instanceof static) { - $this->value = $value->getValue(); - - return; + $value = $value->getValue(); } if (!$this->isValid($value)) { diff --git a/tests/EnumTest.php b/tests/EnumTest.php index 4253618..9fe9022 100755 --- a/tests/EnumTest.php +++ b/tests/EnumTest.php @@ -320,4 +320,15 @@ public function testUnserialize() $this->assertEquals(EnumFixture::FOO, $value->getValue()); $this->assertTrue(EnumFixture::FOO()->equals($value)); } + + /** + * @see https://github.com/myclabs/php-enum/issues/95 + */ + public function testEnumValuesInheritance() + { + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage("Value 'value' is not part of the enum MyCLabs\Tests\Enum\EnumFixture"); + $inheritedEnumFixture = InheritedEnumFixture::VALUE(); + new EnumFixture($inheritedEnumFixture); + } } diff --git a/tests/InheritedEnumFixture.php b/tests/InheritedEnumFixture.php new file mode 100644 index 0000000..301f9bb --- /dev/null +++ b/tests/InheritedEnumFixture.php @@ -0,0 +1,14 @@ +