Skip to content

Commit 9ff56ab

Browse files
authored
Merge pull request #155 from marc-mabe/notClonableError
fix error on `clone $enum`
2 parents 207002c + 4e160b1 commit 9ff56ab

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

src/Enum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function __toString(): string
8181
* @throws LogicException Enums are not cloneable
8282
* because instances are implemented as singletons
8383
*/
84-
final protected function __clone()
84+
final public function __clone()
8585
{
8686
throw new LogicException('Enums are not cloneable');
8787
}

tests/MabeEnumTest/EnumTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,10 @@ public function testCloneNotCallableAndThrowsLogicException(): void
355355

356356
$reflectionClass = new ReflectionClass($enum);
357357
$reflectionMethod = $reflectionClass->getMethod('__clone');
358-
$this->assertTrue($reflectionMethod->isProtected(), 'The method __clone must be protected');
359358
$this->assertTrue($reflectionMethod->isFinal(), 'The method __clone must be final');
360359

361-
$reflectionMethod->setAccessible(true);
362360
$this->expectException(LogicException::class);
363-
$reflectionMethod->invoke($enum);
361+
clone $enum;
364362
}
365363

366364
public function testNotSerializable(): void

0 commit comments

Comments
 (0)