Skip to content

Commit f022f5f

Browse files
committed
Fixed window path bug while looking for the vendor/ dir
1 parent 89d5708 commit f022f5f

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/FileManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function createFinder(string $in)
127127

128128
public function isPathInVendor(string $path): bool
129129
{
130-
return 0 === strpos($path, $this->rootDirectory.'/vendor/');
130+
return 0 === strpos($this->normalizeSlashes($path), $this->normalizeSlashes($this->rootDirectory.'/vendor/'));
131131
}
132132

133133
public function absolutizePath($path): string

tests/FileManagerTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,46 @@ public function getAbsolutePathTests()
8787
'D:/foo/bar',
8888
];
8989
}
90+
91+
/**
92+
* @dataProvider getIsPathInVendorTests
93+
*/
94+
public function testIsPathInVendor(string $rootDir, string $path, bool $expectedIsInVendor)
95+
{
96+
$fileManager = new FileManager(new Filesystem(), $this->createMock(AutoloaderUtil::class), $rootDir);
97+
$this->assertSame($expectedIsInVendor, $fileManager->isPathInVendor($path));
98+
}
99+
100+
public function getIsPathInVendorTests()
101+
{
102+
yield 'not_in_vendor' => [
103+
'/home/project/',
104+
'/home/project/foo/bar',
105+
false,
106+
];
107+
108+
yield 'in_vendor' => [
109+
'/home/project/',
110+
'/home/project/vendor/foo',
111+
true,
112+
];
113+
114+
yield 'not_in_this_vendor' => [
115+
'/home/project/',
116+
'/other/path/vendor/foo',
117+
false,
118+
];
119+
120+
yield 'windows_not_in_vendor' => [
121+
'D:\path\to\project',
122+
'D:\path\to\project\src\foo',
123+
false,
124+
];
125+
126+
yield 'windows_in_vendor' => [
127+
'D:\path\to\project',
128+
'D:\path\to\project\vendor\foo',
129+
true,
130+
];
131+
}
90132
}

0 commit comments

Comments
 (0)