diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 71f52fd..8a91af4 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -121,14 +121,12 @@ protected function formatExpectedPatch($patch) { if ('\\' === DIRECTORY_SEPARATOR) { $formatLine = function ($line) { - if (0 === strpos($line, '---') || 0 === strpos($line, '+++')) { - $line = preg_replace('~/(?getRelativePath(), DIRECTORY_SEPARATOR); + $separator = DIRECTORY_SEPARATOR; if (preg_match('(^([a-z]+:\/\/))', $file, $matches)) { $file = substr($file, strlen($matches[1])); + $separator = '/'; } - $parts = explode(DIRECTORY_SEPARATOR, ltrim($this->getRelativePath(), DIRECTORY_SEPARATOR)); + $parts = explode($separator, $file); $namespace = array(); foreach ($parts as $part) { @@ -120,4 +127,3 @@ private function startsWithLowerCase($string) return isset($string[0]) && strtolower($string[0]) === $string[0]; } } - diff --git a/src/test/QafooLabs/Refactoring/Domain/Model/FileTest.php b/src/test/QafooLabs/Refactoring/Domain/Model/FileTest.php index e66927e..8ad711b 100644 --- a/src/test/QafooLabs/Refactoring/Domain/Model/FileTest.php +++ b/src/test/QafooLabs/Refactoring/Domain/Model/FileTest.php @@ -34,11 +34,20 @@ public function testGetRelativePathRespectsMixedWindowsPathsAndWorkingDirectoryT $this->assertEquals("Foo\Bar.php", $file->getRelativePath()); } + public function testRelativePathConstructionForAbsoluteVFSFiles() + { + $src = $this->createFileSystem()->getChild('src')->url(); + $bar = $src.DIRECTORY_SEPARATOR.'Foo'.DIRECTORY_SEPARATOR.'Bar.php'; + + $file = File::createFromPath($bar, $notRelatedWorkingDir = __DIR__); + $this->assertEquals('vfs://project/src/Foo/Bar.php', $file->getRelativePath()); + } + static public function dataExtractPsr0ClassName() { return array( - array(new PhpName('Foo', 'Foo'), 'src/Foo.php'), - array(new PhpName('Foo\Bar', 'Bar'), 'src/Foo/Bar.php'), + array(new PhpName('Foo', 'Foo'), 'src'.DIRECTORY_SEPARATOR.'Foo.php'), + array(new PhpName('Foo\Bar', 'Bar'), 'src'.DIRECTORY_SEPARATOR.'Foo'.DIRECTORY_SEPARATOR.'Bar.php'), ); }