diff --git a/src/Mapping/Driver/SymfonyFileLocator.php b/src/Mapping/Driver/SymfonyFileLocator.php index 09339fae..553c5150 100644 --- a/src/Mapping/Driver/SymfonyFileLocator.php +++ b/src/Mapping/Driver/SymfonyFileLocator.php @@ -11,10 +11,8 @@ use RuntimeException; use function array_keys; -use function assert; use function is_dir; use function is_file; -use function is_int; use function realpath; use function sprintf; use function str_replace; @@ -222,12 +220,12 @@ public function findMappingFile(string $className): string } } - $pos = strrpos($className, '\\'); - assert(is_int($pos)); + $pos = strrpos($className, '\\'); + $shortClassName = $pos === false ? $className : substr($className, $pos + 1); throw MappingException::mappingFileNotFound( $className, - substr($className, $pos + 1) . $this->fileExtension, + $shortClassName . $this->fileExtension, ); } diff --git a/tests/Mapping/SymfonyFileLocatorTest.php b/tests/Mapping/SymfonyFileLocatorTest.php index ff7767d8..0b58d5b4 100644 --- a/tests/Mapping/SymfonyFileLocatorTest.php +++ b/tests/Mapping/SymfonyFileLocatorTest.php @@ -188,6 +188,15 @@ public function testFindMappingFileNotFound(): void $locator->findMappingFile('Foo\\stdClass2'); } + public function testFindMappingFileNotFoundForClassInRootNamespace(): void + { + $locator = new SymfonyFileLocator([], '.yml'); + + $this->expectException(MappingException::class); + $this->expectExceptionMessage("No mapping file found named 'DateTime.yml' for class 'DateTime'."); + $locator->findMappingFile('DateTime'); + } + public function testFindMappingFileLeastSpecificNamespaceFirst(): void { // Low -> High