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)
167
167
*
168
168
* @param static|null|bool|int|float|string|array $enumerator An enumerator object or value
169
169
* @return static
170
- * @throws InvalidArgumentException On an unknwon or invalid value
170
+ * @throws InvalidArgumentException On an unknown or invalid value
171
171
* @throws LogicException On ambiguous constant values
172
172
*/
173
173
final public static function get ($ enumerator )
@@ -184,7 +184,7 @@ final public static function get($enumerator)
184
184
*
185
185
* @param null|bool|int|float|string|array $value Enumerator value
186
186
* @return static
187
- * @throws InvalidArgumentException On an unknwon or invalid value
187
+ * @throws InvalidArgumentException On an unknown or invalid value
188
188
* @throws LogicException On ambiguous constant values
189
189
*/
190
190
final public static function byValue ($ value )
@@ -423,6 +423,6 @@ private static function noAmbiguousValues($constants)
423
423
*/
424
424
final public static function __callStatic (string $ method , array $ args )
425
425
{
426
- return self ::byName ($ method );
426
+ return static ::byName ($ method );
427
427
}
428
428
}
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ trait EnumSerializableTrait
24
24
{
25
25
/**
26
26
* The method will be defined by MabeEnum\Enum
27
- * @return null|bool|int|float|string
27
+ * @return null|bool|int|float|string|array
28
28
*/
29
29
abstract public function getValue ();
30
30
@@ -49,7 +49,7 @@ public function serialize(): string
49
49
public function unserialize ($ serialized ): void
50
50
{
51
51
$ value = \unserialize ($ serialized );
52
- $ constants = self ::getConstants ();
52
+ $ constants = static ::getConstants ();
53
53
$ name = \array_search ($ value , $ constants , true );
54
54
if ($ name === false ) {
55
55
$ message = \is_scalar ($ value )
Original file line number Diff line number Diff line change 4
4
5
5
use LogicException ;
6
6
use MabeEnum \Enum ;
7
+ use MabeEnumTest \TestAsset \ExtendedSerializableEnum ;
7
8
use MabeEnumTest \TestAsset \SerializableEnum ;
8
9
use PHPUnit \Framework \TestCase ;
9
10
use ReflectionClass ;
@@ -65,6 +66,18 @@ public function testUnserializeThrowsLogicExceptionOnChangingValue()
65
66
$ enum ->unserialize (serialize (SerializableEnum::STR ));
66
67
}
67
68
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
+
68
81
/**
69
82
* Clears all instantiated enumerations and detected constants of the given enumerator
70
83
* @param string $enumeration
Original file line number Diff line number Diff line change @@ -101,10 +101,22 @@ public function testEnumInheritance()
101
101
), EnumInheritance::getConstants ());
102
102
103
103
$ enum = EnumInheritance::get (EnumInheritance::ONE );
104
+ $ this ->assertInstanceOf (EnumInheritance::class, $ enum );
104
105
$ this ->assertSame (EnumInheritance::ONE , $ enum ->getValue ());
105
106
$ this ->assertSame (0 , $ enum ->getOrdinal ());
106
107
107
108
$ 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 );
108
120
$ this ->assertSame (EnumInheritance::INHERITANCE , $ enum ->getValue ());
109
121
$ this ->assertSame (17 , $ enum ->getOrdinal ());
110
122
}
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