diff --git a/tests/Queue/QueueSyncQueueTest.php b/tests/Queue/QueueSyncQueueTest.php index 2064add943a8..d4d07bbb2d6a 100755 --- a/tests/Queue/QueueSyncQueueTest.php +++ b/tests/Queue/QueueSyncQueueTest.php @@ -6,8 +6,11 @@ use Illuminate\Container\Container; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Queue\QueueableEntity; +use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\Jobs\SyncJob; use Illuminate\Queue\SyncQueue; +use LogicException; use Mockery as m; use PHPUnit\Framework\TestCase; @@ -54,6 +57,26 @@ public function testFailedJobGetsHandledWhenAnExceptionIsThrown() Container::setInstance(); } + + public function testCreatesPayloadObject() + { + $sync = new SyncQueue; + $container = new Container; + $container->bind(\Illuminate\Contracts\Events\Dispatcher::class, \Illuminate\Events\Dispatcher::class); + $container->bind(\Illuminate\Contracts\Bus\Dispatcher::class, \Illuminate\Bus\Dispatcher::class); + $container->bind(\Illuminate\Contracts\Container\Container::class, \Illuminate\Container\Container::class); + $sync->setContainer($container); + + SyncQueue::createPayloadUsing(function ($connection, $queue, $payload) { + return ['data' => ['extra' => 'extraValue']]; + }); + + try { + $sync->push(new SyncQueueJob()); + } catch (LogicException $e) { + $this->assertEquals('extraValue', $e->getMessage()); + } + } } class SyncQueueTestEntity implements QueueableEntity @@ -94,3 +117,20 @@ public function failed() $_SERVER['__sync.failed'] = true; } } + +class SyncQueueJob implements ShouldQueue +{ + use InteractsWithQueue; + + public function handle() + { + throw new LogicException($this->getValueFromJob('extra')); + } + + public function getValueFromJob($key) + { + $payload = $this->job->payload(); + + return $payload['data'][$key] ?? null; + } +}