diff --git a/src/Tempest/Core/src/Kernel/FinishDeferredTasks.php b/src/Tempest/Core/src/Kernel/FinishDeferredTasks.php index c8e901fe3..5db121aa2 100644 --- a/src/Tempest/Core/src/Kernel/FinishDeferredTasks.php +++ b/src/Tempest/Core/src/Kernel/FinishDeferredTasks.php @@ -4,19 +4,21 @@ namespace Tempest\Core\Kernel; +use Tempest\Container\Container; use Tempest\Core\DeferredTasks; final readonly class FinishDeferredTasks { public function __construct( private DeferredTasks $deferredTasks, + private Container $container, ) { } public function __invoke(): void { foreach ($this->deferredTasks->getTasks() as $task) { - $task(); + $this->container->invoke($task); } } } diff --git a/tests/Integration/Core/DeferredTasksTest.php b/tests/Integration/Core/DeferredTasksTest.php index 35cf227a8..dee93e0df 100644 --- a/tests/Integration/Core/DeferredTasksTest.php +++ b/tests/Integration/Core/DeferredTasksTest.php @@ -4,7 +4,9 @@ namespace Tests\Tempest\Integration\Core; +use Tempest\Container\Container; use Tempest\Core\Kernel\FinishDeferredTasks; +use function Tempest\defer; use function Tempest\uri; use Tests\Tempest\Fixtures\Controllers\DeferController; use Tests\Tempest\Integration\FrameworkIntegrationTestCase; @@ -22,8 +24,23 @@ public function test_deferred_tasks_are_executed(): void ->get(uri(DeferController::class)) ->assertOk(); - $this->container->get(FinishDeferredTasks::class)(); + $this->container->invoke(FinishDeferredTasks::class); $this->assertTrue(DeferController::$executed); } + + public function test_deferred_tasks_are_executed_with_container_parameters(): void + { + $executed = false; + + defer(function (Container $container) use (&$executed): void { + $container->invoke(function () use (&$executed): void { + $executed = true; + }); + }); + + $this->container->invoke(FinishDeferredTasks::class); + + $this->assertTrue($executed); + } }