Skip to content
Open
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
8 changes: 3 additions & 5 deletions src/Mapping/Driver/SymfonyFileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
);
}

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