diff --git a/src/Mapping/Driver/SymfonyFileLocator.php b/src/Mapping/Driver/SymfonyFileLocator.php index 09339fae..5d9b1ceb 100644 --- a/src/Mapping/Driver/SymfonyFileLocator.php +++ b/src/Mapping/Driver/SymfonyFileLocator.php @@ -11,16 +11,14 @@ use RuntimeException; use function array_keys; -use function assert; +use function basename; use function is_dir; use function is_file; -use function is_int; use function realpath; use function sprintf; use function str_replace; use function str_starts_with; use function strlen; -use function strrpos; use function strtr; use function substr; @@ -222,12 +220,9 @@ public function findMappingFile(string $className): string } } - $pos = strrpos($className, '\\'); - assert(is_int($pos)); - throw MappingException::mappingFileNotFound( $className, - substr($className, $pos + 1) . $this->fileExtension, + basename(str_replace('\\', '/', $className)) . $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