Skip to content

Commit

Permalink
Fixed window path bug while looking for the vendor/ dir
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed Feb 27, 2018
1 parent 89d5708 commit f022f5f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions tests/FileManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
}

0 comments on commit f022f5f

Please sign in to comment.