Skip to content

Commit 0f060e9

Browse files
committed
bug #1370 Entity Validator is accepting absolute namespaces (Antarian)
This PR was merged into the 1.x-dev branch. Discussion ---------- Entity Validator is accepting absolute namespaces Resolving issue when Absolute namespace for Entity is not passing through validation even if it should. #1365 (comment) Commits ------- 3a41391 Entity Validator is accepting absolute namespaces
2 parents f154efd + 3a41391 commit 0f060e9

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Validator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public static function entityExists(string $className = null, array $entities =
216216
self::classExists($className, sprintf('Entity "%s" doesn\'t exist; please enter an existing one or create a new one.', $className));
217217
}
218218

219-
if (!\in_array($className, $entities)) {
219+
if (!\in_array($className, $entities) && !\in_array(ltrim($className, '\\'), $entities)) {
220220
throw new RuntimeCommandException(sprintf('Entity "%s" doesn\'t exist; please enter an existing one or create a new one.', $className));
221221
}
222222

tests/ValidatorTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,26 @@ public function testInvalidEncodingInClassName()
9494
$this->expectExceptionMessage(sprintf('"%sController" is not a UTF-8-encoded string.', \chr(0xA6)));
9595
Validator::validateClassName(mb_convert_encoding('ŚController', 'ISO-8859-2', 'UTF-8'));
9696
}
97+
98+
public function testRegisteredEntitiesExists()
99+
{
100+
$this->expectException(RuntimeCommandException::class);
101+
$this->expectExceptionMessage('There are no registered entities; please create an entity before using this command.');
102+
Validator::entityExists('App\Entity\Class', []);
103+
}
104+
105+
public function testEntityExists()
106+
{
107+
$className = self::class;
108+
$this->assertSame($className, Validator::entityExists($className, [$className]));
109+
$this->assertSame('\\'.$className, Validator::entityExists('\\'.$className, [$className]));
110+
}
111+
112+
public function testEntityDoesNotExist()
113+
{
114+
$className = '\\'.self::class;
115+
$this->expectException(RuntimeCommandException::class);
116+
$this->expectExceptionMessage(sprintf('Entity "%s" doesn\'t exist; please enter an existing one or create a new one.', $className));
117+
Validator::entityExists($className, ['Full\Entity\DummyEntity']);
118+
}
97119
}

0 commit comments

Comments
 (0)