From 51ed29f59adc5dc9511afe04359845bd750e99db Mon Sep 17 00:00:00 2001 From: broux Date: Wed, 15 Jan 2014 17:35:18 -1000 Subject: [PATCH] allowing namespaces containing Spec like Specification (fix #5) --- src/PhpSpec/Symfony2Extension/Locator/PSR0Locator.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/PhpSpec/Symfony2Extension/Locator/PSR0Locator.php b/src/PhpSpec/Symfony2Extension/Locator/PSR0Locator.php index df1b813..56ce887 100644 --- a/src/PhpSpec/Symfony2Extension/Locator/PSR0Locator.php +++ b/src/PhpSpec/Symfony2Extension/Locator/PSR0Locator.php @@ -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); } @@ -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)) {