Skip to content

Commit

Permalink
[8.x] Add test case for #36998 (#37003)
Browse files Browse the repository at this point in the history
* Add test case for #36998

* Apply fixes from StyleCI (#37002)
  • Loading branch information
jbrooksuk committed Apr 15, 2021
1 parent 6116d51 commit f6721f0
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/Queue/QueueSyncQueueTest.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}

0 comments on commit f6721f0

Please sign in to comment.