Skip to content

Commit

Permalink
allowing namespaces containing Spec like Specification (fix phpspec#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
broux committed Jan 16, 2014
1 parent 2dd925f commit 51ed29f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/PhpSpec/Symfony2Extension/Locator/PSR0Locator.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ public function findResources($query)
private function createResourceFromSpecFile($path)
{
$relativePath = substr($path, strlen($this->srcPath), -4);
$relativePath = str_replace('Spec', '', $relativePath);
$relativePath = str_replace('/Spec/', '//', $relativePath);
if (strrpos($relativePath, 'Spec') == strlen($relativePath) - 4) {
$relativePath = substr($relativePath, 0, -4);
}

return $this->createResource($relativePath);
}
Expand Down Expand Up @@ -208,7 +211,10 @@ public function supportsClass($classname)
public function createResource($classname)
{
$classname = str_replace('/', '\\', $classname);
$classname = str_replace(array($this->specSubNamespace, 'Spec'), '', $classname);
$classname = str_replace(array('\\Spec\\', '\\'.$this->specSubNamespace.'\\'), '\\\\', $classname);
if (strrpos($classname, 'Spec') == strlen($classname) - 4) {
$classname = substr($classname, 0, -4);
}
$classname = str_replace('\\\\', '\\', $classname);

if ('' === $this->srcNamespace || 0 === strpos($classname, $this->srcNamespace)) {
Expand Down

0 comments on commit 51ed29f

Please sign in to comment.