PendingChainFake.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. * @return void
  21. */
  22. public function __construct(BusFake $bus, $job, $chain)
  23. {
  24. $this->bus = $bus;
  25. $this->job = $job;
  26. $this->chain = $chain;
  27. }
  28. /**
  29. * Dispatch the job with the given arguments.
  30. *
  31. * @return \Illuminate\Foundation\Bus\PendingDispatch
  32. */
  33. public function dispatch()
  34. {
  35. if (is_string($this->job)) {
  36. $firstJob = new $this->job(...func_get_args());
  37. } elseif ($this->job instanceof Closure) {
  38. $firstJob = CallQueuedClosure::create($this->job);
  39. } else {
  40. $firstJob = $this->job;
  41. }
  42. $firstJob->allOnConnection($this->connection);
  43. $firstJob->allOnQueue($this->queue);
  44. $firstJob->chain($this->chain);
  45. $firstJob->delay($this->delay);
  46. $firstJob->chainCatchCallbacks = $this->catchCallbacks();
  47. return $this->bus->dispatch($firstJob);
  48. }
  49. }