Skip to content

Commit 2f08d94

Browse files
fix(autoloader): trigger autoloader_initialized from Boot and cleanup test listeners
1 parent 7060d87 commit 2f08d94

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

‎system/Autoloader/Autoloader.php‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace CodeIgniter\Autoloader;
1515

1616
use Closure;
17-
use CodeIgniter\Events\Events;
1817
use CodeIgniter\Exceptions\ConfigException;
1918
use CodeIgniter\Exceptions\InvalidArgumentException;
2019
use CodeIgniter\Exceptions\RuntimeException;
@@ -145,8 +144,6 @@ public function initialize(Autoload $config, Modules $modules)
145144
$this->loadComposerAutoloader($modules);
146145
}
147146

148-
Events::trigger('autoloader_initialized', $this);
149-
150147
return $this;
151148
}
152149

‎system/Boot.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use CodeIgniter\Cache\FactoriesCache;
1717
use CodeIgniter\CLI\Console;
1818
use CodeIgniter\Config\DotEnv;
19+
use CodeIgniter\Events\Events;
1920
use Config\App;
2021
use Config\Autoload;
2122
use Config\Modules;
@@ -319,7 +320,12 @@ protected static function loadAutoloader(): void
319320
require_once APPPATH . 'Config/Services.php';
320321

321322
// Initialize and register the loader with the SPL autoloader stack.
322-
Services::autoloader()->initialize(new Autoload(), new Modules())->register();
323+
$autoloader = Services::autoloader()->initialize(new Autoload(), new Modules());
324+
$autoloader->register();
325+
326+
if (function_exists('service')) {
327+
Events::trigger('autoloader_initialized', $autoloader);
328+
}
323329
}
324330

325331
protected static function autoloadHelpers(): void

‎tests/system/Autoloader/AutoloaderTest.php‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use App\Controllers\Home;
1717
use Closure;
18+
use CodeIgniter\Boot;
1819
use CodeIgniter\Events\Events;
1920
use CodeIgniter\Exceptions\ConfigException;
2021
use CodeIgniter\Test\CIUnitTestCase;
@@ -71,6 +72,7 @@ protected function tearDown(): void
7172
parent::tearDown();
7273

7374
$this->loader->unregister();
75+
Events::removeAllListeners('autoloader_initialized');
7476
}
7577

7678
public function testLoadStoredClass(): void
@@ -414,14 +416,10 @@ public function testAutoloaderInitializedEvent(): void
414416
$passedLoader = $loader;
415417
});
416418

417-
$config = new Autoload();
418-
$modules = new Modules();
419-
$modules->discoverInComposer = false;
420-
421-
$loader = new Autoloader();
422-
$loader->initialize($config, $modules);
419+
$method = self::getPrivateMethodInvoker(Boot::class, 'loadAutoloader');
420+
$method();
423421

424422
$this->assertTrue($triggered);
425-
$this->assertSame($loader, $passedLoader);
423+
$this->assertInstanceOf(Autoloader::class, $passedLoader);
426424
}
427425
}

0 commit comments

Comments
 (0)