Skip to content

Commit d49200d

Browse files
committed
bug #214 Fixing a bug where having relativizePath failed if root was /src (weaverryan)
This PR was squashed before being merged into the 1.0-dev branch (closes #214). Discussion ---------- Fixing a bug where having relativizePath failed if root was /src Thanks to @yann-eugone for helping to spot & debug this! Commits ------- 5c8bbba fixing cs 6c1d168 Fixing a bug where having relativizePath failed if root was /src
2 parents 2ca7aea + 5c8bbba commit d49200d

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/FileManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public function relativizePath($absolutePath): string
100100

101101
$absolutePath = $this->realPath($absolutePath);
102102

103-
$relativePath = ltrim(str_replace($this->rootDirectory, '', $absolutePath), '/');
103+
// str_replace but only the first occurrence
104+
$relativePath = ltrim(implode('', explode($this->rootDirectory, $absolutePath, 2)), '/');
104105
if (0 === strpos($relativePath, './')) {
105106
$relativePath = substr($relativePath, 2);
106107
}

src/Test/MakerTestEnvironment.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ private function __construct(MakerTestDetails $testDetails)
5656
$this->cachePath = realpath($cachePath);
5757
$this->flexPath = $this->cachePath.'/flex_project';
5858

59-
$this->path = $this->cachePath.DIRECTORY_SEPARATOR.$testDetails->getUniqueCacheDirectoryName();
59+
$this->path = $this->cachePath.\DIRECTORY_SEPARATOR.$testDetails->getUniqueCacheDirectoryName();
6060

61-
$this->snapshotFile = $this->path.DIRECTORY_SEPARATOR.basename($this->path).'.json';
61+
$this->snapshotFile = $this->path.\DIRECTORY_SEPARATOR.basename($this->path).'.json';
6262
}
6363

6464
public static function create(MakerTestDetails $testDetails): self

tests/FileManagerTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public function getRelativizePathTests()
5050
'D:\path\to\project\vendor\composer/../../src/Controller/TestController.php',
5151
'src/Controller/TestController.php',
5252
];
53+
54+
yield 'double_src' => [
55+
'/src',
56+
'/src/vendor/composer/../../src/Command/FooCommand.php',
57+
'src/Command/FooCommand.php',
58+
];
5359
}
5460

5561
/**

0 commit comments

Comments
 (0)