File tree 2 files changed +15
-0
lines changed
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
40
40
*/
41
41
public function __construct ($ value )
42
42
{
43
+ if ($ value instanceof static) {
44
+ $ this ->value = $ value ->getValue ();
45
+
46
+ return ;
47
+ }
48
+
43
49
if (!$ this ->isValid ($ value )) {
44
50
throw new \UnexpectedValueException ("Value ' $ value' is not part of the enum " . \get_called_class ());
45
51
}
Original file line number Diff line number Diff line change @@ -281,6 +281,15 @@ public function testBooleanEnum()
281
281
$ this ->assertFalse ((new EnumFixture (EnumFixture::PROBLEMATIC_BOOLEAN_FALSE ))->jsonSerialize ());
282
282
}
283
283
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
+
284
293
private function assertJsonEqualsJson ($ json1 , $ json2 )
285
294
{
286
295
$ this ->assertJsonStringEqualsJsonString ($ json1 , $ json2 );
You can’t perform that action at this time.
0 commit comments