From af443b86d1ed968f7cf8678b05ee635db58252a3 Mon Sep 17 00:00:00 2001 From: Auke Terpstra Date: Wed, 7 Feb 2024 21:08:05 +0100 Subject: [PATCH] The command returned from getCommandProperties() is an array, so use it as an array. Use the connection from the task or fallback to the default. --- src/TaskHandler.php | 6 +----- tests/TaskHandlerTest.php | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/TaskHandler.php b/src/TaskHandler.php index 8be84c3..434e8f8 100644 --- a/src/TaskHandler.php +++ b/src/TaskHandler.php @@ -13,7 +13,6 @@ use Illuminate\Support\Str; use Illuminate\Validation\ValidationException; use Safe\Exceptions\JsonException; -use stdClass; use UnexpectedValueException; use function Safe\json_decode; @@ -98,11 +97,8 @@ private function captureTask($task): array private function loadQueueConnectionConfiguration(array $task): void { - /** - * @var stdClass $command - */ $command = self::getCommandProperties($task['data']['command']); - $connection = $command->connection ?? config('queue.default'); + $connection = $command['connection'] ?? config('queue.default'); $baseConfig = config('queue.connections.' . $connection); $config = (new CloudTasksConnector())->connect($baseConfig)->config; diff --git a/tests/TaskHandlerTest.php b/tests/TaskHandlerTest.php index 5cc4292..b100da6 100644 --- a/tests/TaskHandlerTest.php +++ b/tests/TaskHandlerTest.php @@ -222,6 +222,26 @@ public function it_can_run_a_task() Log::assertLogged('SimpleJob:success'); } + /** + * @test + */ + public function it_can_run_a_task_using_the_task_connection() + { + // Arrange + OpenIdVerificator::fake(); + Log::swap(new LogFake()); + Event::fake([JobProcessing::class, JobProcessed::class]); + $this->app['config']->set('queue.default', 'non-existing-connection'); + + // Act + $job = new SimpleJob(); + $job->connection = 'my-cloudtasks-connection'; + $this->dispatch($job)->runWithoutExceptionHandler(); + + // Assert + Log::assertLogged('SimpleJob:success'); + } + /** * @test */