Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/Mapping/Driver/SymfonyFileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
);
}

Expand Down
9 changes: 9 additions & 0 deletions tests/Mapping/SymfonyFileLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down