diff --git a/src/FileManager.php b/src/FileManager.php index b71b4716c..0e890b541 100644 --- a/src/FileManager.php +++ b/src/FileManager.php @@ -127,7 +127,7 @@ public function createFinder(string $in) public function isPathInVendor(string $path): bool { - return 0 === strpos($path, $this->rootDirectory.'/vendor/'); + return 0 === strpos($this->normalizeSlashes($path), $this->normalizeSlashes($this->rootDirectory.'/vendor/')); } public function absolutizePath($path): string diff --git a/tests/FileManagerTest.php b/tests/FileManagerTest.php index bcb6f23e6..54e8558c4 100644 --- a/tests/FileManagerTest.php +++ b/tests/FileManagerTest.php @@ -87,4 +87,46 @@ public function getAbsolutePathTests() 'D:/foo/bar', ]; } + + /** + * @dataProvider getIsPathInVendorTests + */ + public function testIsPathInVendor(string $rootDir, string $path, bool $expectedIsInVendor) + { + $fileManager = new FileManager(new Filesystem(), $this->createMock(AutoloaderUtil::class), $rootDir); + $this->assertSame($expectedIsInVendor, $fileManager->isPathInVendor($path)); + } + + public function getIsPathInVendorTests() + { + yield 'not_in_vendor' => [ + '/home/project/', + '/home/project/foo/bar', + false, + ]; + + yield 'in_vendor' => [ + '/home/project/', + '/home/project/vendor/foo', + true, + ]; + + yield 'not_in_this_vendor' => [ + '/home/project/', + '/other/path/vendor/foo', + false, + ]; + + yield 'windows_not_in_vendor' => [ + 'D:\path\to\project', + 'D:\path\to\project\src\foo', + false, + ]; + + yield 'windows_in_vendor' => [ + 'D:\path\to\project', + 'D:\path\to\project\vendor\foo', + true, + ]; + } }