QueueRedisJobTest.php 1.5 KB

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