Skip to content

Commit a39155a

Browse files
authored
🩹 Fix app registration callbacks not being called (Fixes #463) (#464)
✅ Add tests for registered, booting and booted callbacks
1 parent e8c787d commit a39155a

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

‎src/Roots/Acorn/Application.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ public function registerConfiguredProviders()
329329

330330
(new ProviderRepository($this, new Filesystem, $this->getCachedServicesPath()))
331331
->load($providers->collapse()->toArray());
332+
333+
$this->fireAppCallbacks($this->registeredCallbacks);
332334
}
333335

334336
/**

‎tests/Application/ApplicationTest.php‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,72 @@ public function boot()
205205
$app->boot();
206206
});
207207

208+
it('calls registered callbacks', function () {
209+
$app = new Application(temp('base_path'));
210+
211+
mkdir($app->storagePath('framework/cache'), 0777, true);
212+
213+
$app->bind('config', fn () => new ConfigRepository);
214+
215+
$manifest = mock(\Roots\Acorn\PackageManifest::class);
216+
217+
$app->singleton(\Illuminate\Foundation\PackageManifest::class, fn () => $manifest);
218+
219+
$manifest
220+
->shouldReceive('providers')
221+
->andReturn([]);
222+
223+
$callback = Mockery::mock(new class
224+
{
225+
public function __invoke(...$args) {}
226+
});
227+
228+
$callback
229+
->shouldReceive('__invoke')
230+
->withArgs([$app])
231+
->once();
232+
233+
$app->registered($callback);
234+
235+
$app->registerConfiguredProviders();
236+
});
237+
238+
it('calls booting callbacks', function () {
239+
$app = new Application;
240+
241+
$callback = Mockery::mock(new class
242+
{
243+
public function __invoke(...$args) {}
244+
});
245+
246+
$callback
247+
->shouldReceive('__invoke')
248+
->withArgs([$app])
249+
->once();
250+
251+
$app->booting($callback);
252+
253+
$app->boot();
254+
});
255+
256+
it('calls booted callbacks', function () {
257+
$app = new Application;
258+
259+
$callback = Mockery::mock(new class
260+
{
261+
public function __invoke(...$args) {}
262+
});
263+
264+
$callback
265+
->shouldReceive('__invoke')
266+
->withArgs([$app])
267+
->once();
268+
269+
$app->booted($callback);
270+
271+
$app->boot();
272+
});
273+
208274
it('uses custom aliases', function () {
209275
$app = new Application;
210276

0 commit comments

Comments
 (0)