File tree Expand file tree Collapse file tree 5 files changed +45
-5
lines changed Expand file tree Collapse file tree 5 files changed +45
-5
lines changed Original file line number Diff line number Diff line change @@ -167,7 +167,7 @@ final public function is($enumerator)
167167 *
168168 * @param static|null|bool|int|float|string|array $enumerator An enumerator object or value
169169 * @return static
170- * @throws InvalidArgumentException On an unknwon or invalid value
170+ * @throws InvalidArgumentException On an unknown or invalid value
171171 * @throws LogicException On ambiguous constant values
172172 */
173173 final public static function get ($ enumerator )
@@ -184,7 +184,7 @@ final public static function get($enumerator)
184184 *
185185 * @param null|bool|int|float|string|array $value Enumerator value
186186 * @return static
187- * @throws InvalidArgumentException On an unknwon or invalid value
187+ * @throws InvalidArgumentException On an unknown or invalid value
188188 * @throws LogicException On ambiguous constant values
189189 */
190190 final public static function byValue ($ value )
@@ -423,6 +423,6 @@ private static function noAmbiguousValues($constants)
423423 */
424424 final public static function __callStatic (string $ method , array $ args )
425425 {
426- return self ::byName ($ method );
426+ return static ::byName ($ method );
427427 }
428428}
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ trait EnumSerializableTrait
2424{
2525 /**
2626 * The method will be defined by MabeEnum\Enum
27- * @return null|bool|int|float|string
27+ * @return null|bool|int|float|string|array
2828 */
2929 abstract public function getValue ();
3030
@@ -49,7 +49,7 @@ public function serialize(): string
4949 public function unserialize ($ serialized ): void
5050 {
5151 $ value = \unserialize ($ serialized );
52- $ constants = self ::getConstants ();
52+ $ constants = static ::getConstants ();
5353 $ name = \array_search ($ value , $ constants , true );
5454 if ($ name === false ) {
5555 $ message = \is_scalar ($ value )
Original file line number Diff line number Diff line change 44
55use LogicException ;
66use MabeEnum \Enum ;
7+ use MabeEnumTest \TestAsset \ExtendedSerializableEnum ;
78use MabeEnumTest \TestAsset \SerializableEnum ;
89use PHPUnit \Framework \TestCase ;
910use ReflectionClass ;
@@ -65,6 +66,18 @@ public function testUnserializeThrowsLogicExceptionOnChangingValue()
6566 $ enum ->unserialize (serialize (SerializableEnum::STR ));
6667 }
6768
69+ public function testInheritence ()
70+ {
71+ $ enum = ExtendedSerializableEnum::EXTENDED ();
72+
73+ $ serialized = serialize ($ enum );
74+ $ this ->assertInternalType ('string ' , $ serialized );
75+
76+ $ unserialized = unserialize ($ serialized );
77+ $ this ->assertInstanceOf (ExtendedSerializableEnum::class, $ unserialized );
78+ $ this ->assertSame ($ enum ->getValue (), $ unserialized ->getValue ());
79+ }
80+
6881 /**
6982 * Clears all instantiated enumerations and detected constants of the given enumerator
7083 * @param string $enumeration
Original file line number Diff line number Diff line change @@ -101,10 +101,22 @@ public function testEnumInheritance()
101101 ), EnumInheritance::getConstants ());
102102
103103 $ enum = EnumInheritance::get (EnumInheritance::ONE );
104+ $ this ->assertInstanceOf (EnumInheritance::class, $ enum );
104105 $ this ->assertSame (EnumInheritance::ONE , $ enum ->getValue ());
105106 $ this ->assertSame (0 , $ enum ->getOrdinal ());
106107
107108 $ enum = EnumInheritance::get (EnumInheritance::INHERITANCE );
109+ $ this ->assertInstanceOf (EnumInheritance::class, $ enum );
110+ $ this ->assertSame (EnumInheritance::INHERITANCE , $ enum ->getValue ());
111+ $ this ->assertSame (17 , $ enum ->getOrdinal ());
112+
113+ $ enum = EnumInheritance::ONE ();
114+ $ this ->assertInstanceOf (EnumInheritance::class, $ enum );
115+ $ this ->assertSame (EnumInheritance::ONE , $ enum ->getValue ());
116+ $ this ->assertSame (0 , $ enum ->getOrdinal ());
117+
118+ $ enum = EnumInheritance::INHERITANCE ();
119+ $ this ->assertInstanceOf (EnumInheritance::class, $ enum );
108120 $ this ->assertSame (EnumInheritance::INHERITANCE , $ enum ->getValue ());
109121 $ this ->assertSame (17 , $ enum ->getOrdinal ());
110122 }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace MabeEnumTest \TestAsset ;
4+
5+ /**
6+ * Extended serializable enumeration
7+ *
8+ * @link http://github.com/marc-mabe/php-enum for the canonical source repository
9+ * @copyright Copyright (c) 2017 Marc Bennewitz
10+ * @license http://github.com/marc-mabe/php-enum/blob/master/LICENSE.txt New BSD License
11+ */
12+ class ExtendedSerializableEnum extends SerializableEnum
13+ {
14+ const EXTENDED = 'extended ' ;
15+ }
You can’t perform that action at this time.
0 commit comments