Skip to content

Commit 0a67b26

Browse files
committed
Merge branch 'hotfix/43' of https://github.com/marc-mabe/php-enum
2 parents e82f2b2 + 5d0a9a7 commit 0a67b26

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/MabeEnum/Enum.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ final private function __clone()
7575
throw new LogicException('Enums are not cloneable');
7676
}
7777

78+
/**
79+
* @throws LogicException Enums are not serializable
80+
* because instances are implemented as singletons
81+
*/
82+
final public function __sleep()
83+
{
84+
throw new LogicException('Enums are not serializable');
85+
}
86+
87+
/**
88+
* @throws LogicException Enums are not serializable
89+
* because instances are implemented as singletons
90+
*/
91+
final public function __wakeup()
92+
{
93+
throw new LogicException('Enums are not serializable');
94+
}
95+
7896
/**
7997
* Get the current selected value
8098
*

tests/MabeEnumTest/EnumTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,18 @@ public function testCloneNotCallableAndThrowsLogicException()
239239
$this->setExpectedException('LogicException');
240240
$reflectionMethod->invoke($enum);
241241
}
242+
243+
public function testNotSerializable()
244+
{
245+
$enum = EnumBasic::ONE();
246+
247+
$this->setExpectedException('LogicException');
248+
serialize($enum);
249+
}
250+
251+
public function testNotUnserializable()
252+
{
253+
$this->setExpectedException('LogicException');
254+
unserialize("O:32:\"MabeEnumTest\TestAsset\EnumBasic\":0:{}");
255+
}
242256
}

0 commit comments

Comments
 (0)