Skip to content

Commit af63960

Browse files
committed
Prevent enum FQCN to have double backslashes
1 parent dcd2260 commit af63960

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Validator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ public static function classExists(string $className, string $errorMessage = '')
195195
{
196196
self::notBlank($className);
197197

198+
// normalize class name
199+
$className = str_replace('\\\\', '\\', $className);
200+
198201
if (!class_exists($className)) {
199202
$errorMessage = $errorMessage ?: \sprintf('Class "%s" doesn\'t exist; please enter an existing full class name.', $className);
200203

@@ -247,7 +250,7 @@ public static function classIsUserInterface($userClassName): string
247250

248251
public static function classIsBackedEnum($backedEnum): string
249252
{
250-
self::classExists($backedEnum);
253+
$backedEnum = self::classExists($backedEnum);
251254

252255
if (!isset(class_implements($backedEnum)[\BackedEnum::class])) {
253256
throw new RuntimeCommandException(\sprintf('The class "%s" is not a valid BackedEnum.', $backedEnum));

tests/Maker/MakeEntityTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,28 @@ public function getTestDetails(): \Generator
762762
$this->runEntityTest($runner);
763763
}),
764764
];
765+
766+
yield 'it_does_not_throw_error_with_double_slashes' => [$this->createMakeEntityTest()
767+
->run(function (MakerTestRunner $runner) {
768+
$this->copyEntity($runner, 'Enum/Role-basic.php');
769+
770+
$runner->runMaker([
771+
// entity class name
772+
'User',
773+
// add additional field
774+
'role',
775+
'enum',
776+
'App\\\\Entity\\\\Enum\\\\Role',
777+
'',
778+
// nullable
779+
'y',
780+
// finish adding fields
781+
'',
782+
]);
783+
784+
$this->runEntityTest($runner);
785+
}),
786+
];
765787
}
766788

767789
/** @param array<string, mixed> $data */

0 commit comments

Comments
 (0)