1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
<?php
namespace Illuminate\Tests\Queue;
use Illuminate\Container\Container;
use Illuminate\Queue\Jobs\RedisJob;
use Illuminate\Queue\RedisQueue;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use stdClass;
class QueueRedisJobTest extends TestCase
{
protected function tearDown(): void
{
m::close();
}
public function testFireProperlyCallsTheJobHandler()
{
$job = $this->getJob();
$job->getContainer()->shouldReceive('make')->once()->with('foo')->andReturn($handler = m::mock(stdClass::class));
$handler->shouldReceive('fire')->once()->with($job, ['data']);
$job->fire();
}
public function testDeleteRemovesTheJobFromRedis()
{
$job = $this->getJob();
$job->getRedisQueue()->shouldReceive('deleteReserved')->once()
->with('default', $job);
$job->delete();
}
public function testReleaseProperlyReleasesJobOntoRedis()
{
$job = $this->getJob();
$job->getRedisQueue()->shouldReceive('deleteAndRelease')->once()
->with('default', $job, 1);
$job->release(1);
}
protected function getJob()
{
return new RedisJob(
m::mock(Container::class),
m::mock(RedisQueue::class),
json_encode(['job' => 'foo', 'data' => ['data'], 'attempts' => 1]),
json_encode(['job' => 'foo', 'data' => ['data'], 'attempts' => 2]),
'connection-name',
'default'
);
}
}
|