File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,12 @@ abstract class Enum implements \JsonSerializable
4040 */
4141 public function __construct ($ value )
4242 {
43+ if ($ value instanceof static) {
44+ $ this ->value = $ value ->getValue ();
45+
46+ return ;
47+ }
48+
4349 if (!$ this ->isValid ($ value )) {
4450 throw new \UnexpectedValueException ("Value ' $ value' is not part of the enum " . \get_called_class ());
4551 }
Original file line number Diff line number Diff line change @@ -281,6 +281,15 @@ public function testBooleanEnum()
281281 $ this ->assertFalse ((new EnumFixture (EnumFixture::PROBLEMATIC_BOOLEAN_FALSE ))->jsonSerialize ());
282282 }
283283
284+ public function testConstructWithSameEnumArgument ()
285+ {
286+ $ enum = new EnumFixture (EnumFixture::FOO );
287+
288+ $ enveloped = new EnumFixture ($ enum );
289+
290+ $ this ->assertEquals ($ enum , $ enveloped );
291+ }
292+
284293 private function assertJsonEqualsJson ($ json1 , $ json2 )
285294 {
286295 $ this ->assertJsonStringEqualsJsonString ($ json1 , $ json2 );
You can’t perform that action at this time.
0 commit comments