@@ -164,6 +164,10 @@ function testIgnoredFileFunc(int $id): int
164164 });
165165
166166 describe ('stream_open() Fast-Paths & Whitelist Preservation ' , function () {
167+ afterEach (function () {
168+ Config::reset ();
169+ });
170+
167171 test ('bypasses AST transformation on non-PHP files ' , function () {
168172 $ wrapper = new StreamWrapper ();
169173 $ openedPath = null ;
@@ -178,67 +182,83 @@ function testIgnoredFileFunc(int $id): int
178182 });
179183
180184 test ('bypasses AST transformation for unwhitelisted vendor files ' , function () {
181- Config::set ([
182- 'include ' => ['src/** ' ],
183- 'exclude ' => ['vendor/** ' ],
184- ]);
185-
186- $ projectRoot = str_replace ('\\' , '/ ' , Config::getProjectRoot ());
187- $ vendorFile = $ projectRoot . '/vendor/composer/autoload_real.php ' ;
188-
189- if (file_exists ($ vendorFile )) {
190- $ wrapper = new StreamWrapper ();
191- $ openedPath = null ;
192- $ success = $ wrapper ->stream_open ($ vendorFile , 'r ' , 0 , $ openedPath );
193-
194- expect ($ success )->toBeTrue ();
195- $ wrapper ->stream_close ();
185+ try {
186+ Config::set ([
187+ 'include ' => ['src/** ' ],
188+ 'exclude ' => ['vendor/** ' ],
189+ ]);
190+
191+ $ projectRoot = str_replace ('\\' , '/ ' , Config::getProjectRoot ());
192+ $ vendorFile = $ projectRoot . '/vendor/composer/autoload_real.php ' ;
193+
194+ if (file_exists ($ vendorFile )) {
195+ $ wrapper = new StreamWrapper ();
196+ $ openedPath = null ;
197+ $ success = $ wrapper ->stream_open ($ vendorFile , 'r ' , 0 , $ openedPath );
198+
199+ expect ($ success )->toBeTrue ();
200+ $ wrapper ->stream_close ();
201+ }
202+ } finally {
203+ Config::reset ();
196204 }
197205 });
198206
199207 test ('transforms whitelisted vendor files when explicitly included in config ' , function () {
200- Config::set ([
201- 'include ' => [
202- 'src/** ' ,
203- 'vendor/monolog/monolog/src/Monolog/Logger.php ' ,
204- ],
205- 'exclude ' => [
206- 'vendor/** ' ,
207- ],
208- ]);
209-
210- $ projectRoot = str_replace ('\\' , '/ ' , Config::getProjectRoot ());
211- $ whitelistedVendorFile = $ projectRoot . '/vendor/monolog/monolog/src/Monolog/Logger.php ' ;
212-
213- expect (FileFilter::isFileExcluded ($ whitelistedVendorFile ))->toBeFalse ();
208+ try {
209+ Config::set ([
210+ 'include ' => [
211+ 'src/** ' ,
212+ 'vendor/monolog/monolog/src/Monolog/Logger.php ' ,
213+ ],
214+ 'exclude ' => [
215+ 'vendor/** ' ,
216+ ],
217+ ]);
218+
219+ $ projectRoot = str_replace ('\\' , '/ ' , Config::getProjectRoot ());
220+ $ whitelistedVendorFile = $ projectRoot . '/vendor/monolog/monolog/src/Monolog/Logger.php ' ;
221+
222+ expect (FileFilter::isFileExcluded ($ whitelistedVendorFile ))->toBeFalse ();
223+ } finally {
224+ Config::reset ();
225+ }
214226 });
215227 });
216228
217229 describe ('Vendor Subpackage Isolation ' , function () {
230+ afterEach (function () {
231+ Config::reset ();
232+ });
233+
218234 test ('strictly isolates vendor files with nested src directories when application includes specific src subpackages ' , function () {
219- Config::set ([
220- 'include ' => [
221- 'src/** ' ,
222- 'src/Core/** ' ,
223- 'src/Storefront/** ' ,
224- 'src/Administration/** ' ,
225- ],
226- 'exclude ' => [
227- 'vendor/** ' ,
228- 'storage/** ' ,
229- 'var/** ' ,
230- 'cache/** ' ,
231- ],
232- ]);
233-
234- $ projectRoot = Config::getProjectRoot ();
235-
236- $ vendorFile = str_replace ('\\' , '/ ' , $ projectRoot . '/vendor/doctrine/dbal/src/Core/Table.php ' );
237- $ appFile = str_replace ('\\' , '/ ' , $ projectRoot . '/src/Core/Framework/Util.php ' );
238-
239- expect (FileFilter::isFileExcluded ($ vendorFile ))->toBeTrue ()
240- ->and (FileFilter::isFileExcluded ($ appFile ))->toBeFalse ()
241- ;
235+ try {
236+ Config::set ([
237+ 'include ' => [
238+ 'src/** ' ,
239+ 'src/Core/** ' ,
240+ 'src/Storefront/** ' ,
241+ 'src/Administration/** ' ,
242+ ],
243+ 'exclude ' => [
244+ 'vendor/** ' ,
245+ 'storage/** ' ,
246+ 'var/** ' ,
247+ 'cache/** ' ,
248+ ],
249+ ]);
250+
251+ $ projectRoot = Config::getProjectRoot ();
252+
253+ $ vendorFile = str_replace ('\\' , '/ ' , $ projectRoot . '/vendor/doctrine/dbal/src/Core/Table.php ' );
254+ $ appFile = str_replace ('\\' , '/ ' , $ projectRoot . '/src/Core/Framework/Util.php ' );
255+
256+ expect (FileFilter::isFileExcluded ($ vendorFile ))->toBeTrue ()
257+ ->and (FileFilter::isFileExcluded ($ appFile ))->toBeFalse ()
258+ ;
259+ } finally {
260+ Config::reset ();
261+ }
242262 });
243263 });
244- });
264+ });
0 commit comments