Skip to content

Commit 12077df

Browse files
committed
Add test for differentiating application folders from vendor folder names in FileFilter
1 parent 80fc704 commit 12077df

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

tests/Contract/VendorIsolationPathTest.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@
3636
StreamWrapper::register();
3737

3838
$projectRoot = Config::getProjectRoot();
39-
4039
$vendorDoctrineFile = str_replace('\\', '/', $projectRoot . '/vendor/doctrine/dbal/src/Schema/AbstractNamedObject.php');
41-
4240
$appFile = str_replace('\\', '/', $projectRoot . '/app/Services/UserService.php');
4341

4442
expect(FileFilter::isFileExcluded($vendorDoctrineFile))->toBeTrue()
@@ -95,4 +93,29 @@
9593

9694
expect(FileFilter::isFileExcluded($vendorFile))->toBeTrue();
9795
});
96+
97+
test('differentiates application folders from identical vendor folder names (e.g. lib/** in app vs lib/** in vendor)', function () {
98+
Config::set([
99+
'include' => [
100+
'lib/**',
101+
'modules/**',
102+
],
103+
'exclude' => [
104+
'vendor/**',
105+
],
106+
]);
107+
108+
StreamWrapper::register();
109+
$projectRoot = Config::getProjectRoot();
110+
111+
$appLibFile = str_replace('\\', '/', $projectRoot . '/lib/Services/PaymentProcessor.php');
112+
$vendorLibFile = str_replace('\\', '/', $projectRoot . '/vendor/dompdf/php-font-lib/lib/Font.php');
113+
expect(FileFilter::isFileExcluded($appLibFile))->toBeFalse();
114+
expect(FileFilter::isFileExcluded($vendorLibFile))->toBeTrue();
115+
116+
$refMethod = new ReflectionMethod(StreamWrapper::class, 'isApplicationFile');
117+
expect($refMethod->invoke(null, $appLibFile, $appLibFile))->toBeTrue()
118+
->and($refMethod->invoke(null, $vendorLibFile, $vendorLibFile))->toBeFalse()
119+
;
120+
});
98121
});

0 commit comments

Comments
 (0)