@@ -385,7 +385,25 @@ public function testReturnsNullWithInternalFunctions(): void
385385
386386 public function testCanAutoloadPsr4ClassesInPotentiallyMultipleDirectories (): void
387387 {
388- spl_autoload_register ([$ this , 'autoload ' ]);
388+ // Force autoload for these asserts because it's not possible to autoload them in the autoload callback
389+ self ::assertFalse (false );
390+ self ::assertTrue (true );
391+
392+ // A test autoloader that simulates Composer PSR-4 autoloader with 2 possible directories for the same namespace
393+ $ autoload = static function (string $ className ): bool {
394+ if ($ className !== AutoloadableClassWithTwoDirectories::class) {
395+ return false ;
396+ }
397+
398+ self ::assertFalse (is_file (__DIR__ . '/AutoloadableClassWithTwoDirectories.php ' ));
399+ self ::assertTrue (is_file (__DIR__ . '/../../Fixture/AutoloadableClassWithTwoDirectories.php ' ));
400+
401+ include __DIR__ . '/../../Fixture/AutoloadableClassWithTwoDirectories.php ' ;
402+
403+ return true ;
404+ };
405+
406+ spl_autoload_register ($ autoload );
389407
390408 self ::assertNotNull (
391409 (new AutoloadSourceLocator ($ this ->astLocator ))
@@ -395,28 +413,11 @@ public function testCanAutoloadPsr4ClassesInPotentiallyMultipleDirectories(): vo
395413 ),
396414 );
397415
398- spl_autoload_unregister ([ $ this , ' autoload ' ] );
416+ spl_autoload_unregister ($ autoload );
399417
400418 self ::assertFalse (class_exists (AutoloadableClassWithTwoDirectories::class, false ));
401419 }
402420
403- /**
404- * A test autoloader that simulates Composer PSR-4 autoloader with 2 possible directories for the same namespace.
405- */
406- public function autoload (string $ className ): bool
407- {
408- if ($ className !== AutoloadableClassWithTwoDirectories::class) {
409- return false ;
410- }
411-
412- self ::assertFalse (is_file (__DIR__ . '/AutoloadableClassWithTwoDirectories.php ' ));
413- self ::assertTrue (is_file (__DIR__ . '/../../Fixture/AutoloadableClassWithTwoDirectories.php ' ));
414-
415- include __DIR__ . '/../../Fixture/AutoloadableClassWithTwoDirectories.php ' ;
416-
417- return true ;
418- }
419-
420421 /**
421422 * @runInSeparateProcess
422423 */
0 commit comments