PendingChainFake.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Illuminate\Support\Testing\Fakes;
  3. use Closure;
  4. use Illuminate\Foundation\Bus\PendingChain;
  5. use Illuminate\Queue\CallQueuedClosure;
  6. class PendingChainFake extends PendingChain
  7. {
  8. /**
  9. * The fake bus instance.
  10. *
  11. * @var \Illuminate\Support\Testing\Fakes\BusFake
  12. */
  13. protected $bus;
  14. /**
  15. * Create a new pending chain instance.
  16. *
  17. * @param \Illuminate\Support\Testing\Fakes\BusFake $bus
  18. * @param mixed $job
  19. * @param array $chain
  20. */
  21. public function __construct(BusFake $bus, $job, $chain)
  22. {
  23. $this->bus = $bus;
  24. $this->job = $job;
  25. $this->chain = $chain;
  26. }
  27. /**
  28. * Dispatch the job with the given arguments.
  29. *
  30. * @return \Illuminate\Foundation\Bus\PendingDispatch
  31. */
  32. public function dispatch()
  33. {
  34. if (is_string($this->job)) {
  35. $firstJob = new $this->job(...func_get_args());
  36. } elseif ($this->job instanceof Closure) {
  37. $firstJob = CallQueuedClosure::create($this->job);
  38. } else {
  39. $firstJob = $this->job;
  40. }
  41. $firstJob->allOnConnection($this->connection);
  42. $firstJob->allOnQueue($this->queue);
  43. $firstJob->chain($this->chain);
  44. $firstJob->delay($this->delay);
  45. $firstJob->chainCatchCallbacks = $this->catchCallbacks();
  46. return $this->bus->dispatch($firstJob);
  47. }
  48. }