File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -41,9 +41,7 @@ abstract class Enum implements \JsonSerializable
4141 public function __construct ($ value )
4242 {
4343 if ($ value instanceof static) {
44- $ this ->value = $ value ->getValue ();
45-
46- return ;
44+ $ value = $ value ->getValue ();
4745 }
4846
4947 if (!$ this ->isValid ($ value )) {
Original file line number Diff line number Diff line change @@ -320,4 +320,15 @@ public function testUnserialize()
320320 $ this ->assertEquals (EnumFixture::FOO , $ value ->getValue ());
321321 $ this ->assertTrue (EnumFixture::FOO ()->equals ($ value ));
322322 }
323+
324+ /**
325+ * @see https://github.com/myclabs/php-enum/issues/95
326+ */
327+ public function testEnumValuesInheritance ()
328+ {
329+ $ this ->expectException (\UnexpectedValueException::class);
330+ $ this ->expectExceptionMessage ("Value 'value' is not part of the enum MyCLabs\Tests\Enum\EnumFixture " );
331+ $ inheritedEnumFixture = InheritedEnumFixture::VALUE ();
332+ new EnumFixture ($ inheritedEnumFixture );
333+ }
323334}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace MyCLabs \Tests \Enum ;
4+
5+ /**
6+ * Class InheritedEnumFixture.
7+ * @package MyCLabs\Tests\Enum
8+ *
9+ * @method static InheritedEnumFixture VALUE()
10+ */
11+ class InheritedEnumFixture extends EnumFixture
12+ {
13+ const VALUE = 'value ' ;
14+ }
You can’t perform that action at this time.
0 commit comments