Skip to content

Commit

Permalink
Merge branch 'hotfix/#367-correct-symfony-file-locator-namespace-matc…
Browse files Browse the repository at this point in the history
…hing-2.6' into 2.6

Close #367
  • Loading branch information
Ocramius committed Dec 25, 2015
2 parents f7dda91 + fc96ca1 commit 50b2308
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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")
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test

0 comments on commit 50b2308

Please sign in to comment.