Skip to content

Commit

Permalink
Merge branch 'hotfix/doctrine#367-correct-symfony-file-locator-namesp…
Browse files Browse the repository at this point in the history
…ace-matching'

Close doctrine#367
  • Loading branch information
Ocramius committed Dec 25, 2015
2 parents 6065c07 + 6d64657 commit 14fd1b0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
Expand Up @@ -153,7 +153,9 @@ public function fileExists($className)
}

$filename = $path.'/'.strtr(substr($className, strlen($prefix)+1), '\\', $this->nsSeparator).$this->fileExtension;
return is_file($filename);
if (is_file($filename)) {
return true;
}
}

return false;
Expand Down Expand Up @@ -230,8 +232,6 @@ public function findMappingFile($className)
if (is_file($filename)) {
return $filename;
}

throw MappingException::mappingFileNotFound($className, $filename);
}

throw MappingException::mappingFileNotFound($className, substr($className, strrpos($className, '\\') + 1).$this->fileExtension);
Expand Down
Expand Up @@ -174,9 +174,37 @@ public function testFindMappingFileNotFound()
$locator = new SymfonyFileLocator([$path => $prefix], ".yml");

$this->setExpectedException(
MappingException::class,
"No mapping file found named '".__DIR__."/_files/stdClass2.yml' for class 'Foo\stdClass2'."
"Doctrine\Common\Persistence\Mapping\MappingException",
"No mapping file found named 'stdClass2.yml' for class 'Foo\stdClass2'."
);
$locator->findMappingFile("Foo\\stdClass2");
}

public function testFindMappingFileLeastSpecificNamespaceFirst()
{
// Low -> High
$prefixes = array();
$prefixes[__DIR__ . "/_match_ns"] = "Foo";
$prefixes[__DIR__ . "/_match_ns/Bar"] = "Foo\\Bar";

$locator = new SymfonyFileLocator($prefixes, ".yml");

$this->assertEquals(
__DIR__ . "/_match_ns/Bar/barEntity.yml",
$locator->findMappingFile("Foo\\Bar\\barEntity")
);
}

public function testFindMappingFileMostSpecificNamespaceFirst() {
$prefixes = array();
$prefixes[__DIR__ . "/_match_ns/Bar"] = "Foo\\Bar";
$prefixes[__DIR__ . "/_match_ns"] = "Foo";

$locator = new SymfonyFileLocator($prefixes, ".yml");

$this->assertEquals(
__DIR__ . "/_match_ns/Bar/barEntity.yml",
$locator->findMappingFile("Foo\\Bar\\barEntity")
);
}
}
@@ -0,0 +1 @@
test
@@ -0,0 +1 @@
test

0 comments on commit 14fd1b0

Please sign in to comment.