File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,13 @@ public function __construct($value)
7474 $ this ->value = $ value ;
7575 }
7676
77+ public function __wakeup ()
78+ {
79+ if ($ this ->key === null ) {
80+ $ this ->key = static ::search ($ this ->value );
81+ }
82+ }
83+
7784 /**
7885 * @param mixed $value
7986 * @return static
@@ -100,10 +107,11 @@ public function getValue()
100107 * Returns the enum key (i.e. the constant name).
101108 *
102109 * @psalm-pure
110+ * @return string
103111 */
104112 public function getKey ()
105113 {
106- return $ this ->key ?? ( $ this -> key = static :: search ( $ this -> value )) ;
114+ return $ this ->key ;
107115 }
108116
109117 /**
Original file line number Diff line number Diff line change @@ -330,7 +330,7 @@ public function testSerialize()
330330 $ this ->assertEquals ($ bin , bin2hex (serialize (EnumFixture::FOO ())));
331331 }
332332
333- public function testUnserialize ()
333+ public function testUnserializeVersionWithoutKey ()
334334 {
335335 // split string for Pretty CI: "Line exceeds 120 characters"
336336 $ bin = '4f3a33303a224d79434c6162735c54657374735c456e756d5c456e756d4669787 ' .
@@ -341,6 +341,22 @@ public function testUnserialize()
341341
342342 $ this ->assertEquals (EnumFixture::FOO , $ value ->getValue ());
343343 $ this ->assertTrue (EnumFixture::FOO ()->equals ($ value ));
344+ $ this ->assertTrue (EnumFixture::FOO () == $ value );
345+ }
346+
347+ public function testUnserialize ()
348+ {
349+ // split string for Pretty CI: "Line exceeds 120 characters"
350+ $ bin = '4f3a33303a224d79434c6162735c54657374735c456e756d5c456e756d4669787 ' .
351+ '4757265223a323a7b733a383a22002a0076616c7565223b733a333a22666f6f223b73 ' .
352+ '3a32323a22004d79434c6162735c456e756d5c456e756d006b6579223b733a333a22464f4f223b7d ' ;
353+
354+ /* @var $value EnumFixture */
355+ $ value = unserialize (pack ('H* ' , $ bin ));
356+
357+ $ this ->assertEquals (EnumFixture::FOO , $ value ->getValue ());
358+ $ this ->assertTrue (EnumFixture::FOO ()->equals ($ value ));
359+ $ this ->assertTrue (EnumFixture::FOO () == $ value );
344360 }
345361
346362 /**
You can’t perform that action at this time.
0 commit comments