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 */