Skip to content

Commit 29e0985

Browse files
authored
Merge pull request #124 from marc-mabe/fix-call-static
Fix call static
2 parents 3304afa + 02e9a2f commit 29e0985

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

src/Enum.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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
}

src/EnumSerializableTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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)

tests/MabeEnumTest/EnumSerializableTraitTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use LogicException;
66
use MabeEnum\Enum;
7+
use MabeEnumTest\TestAsset\ExtendedSerializableEnum;
78
use MabeEnumTest\TestAsset\SerializableEnum;
89
use PHPUnit\Framework\TestCase;
910
use 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

tests/MabeEnumTest/EnumTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

0 commit comments

Comments
 (0)