Debian Codegraph @

lib/3rdParty/composer/illuminate/support/Testing/Fakes/BusFake.php

raw symbols SCIP
1 <?php
2
3 namespace Illuminate\Support\Testing\Fakes;
4
5 use Closure;
6 use Illuminate\Bus\BatchRepository;
7 use Illuminate\Bus\ChainedBatch;
8 use Illuminate\Bus\PendingBatch;
9 use Illuminate\Contracts\Bus\QueueingDispatcher;
10 use Illuminate\Support\Arr;
11 use Illuminate\Support\Collection;
12 use Illuminate\Support\Str;
13 use Illuminate\Support\Traits\ReflectsClosures;
14 use PHPUnit\Framework\Assert as PHPUnit;
15 use RuntimeException;
16
17 class BusFake implements Fake, QueueingDispatcher
18 {
19 use ReflectsClosures;
20
21 /**
22 * The original Bus dispatcher implementation.
23 *
24 * @var \Illuminate\Contracts\Bus\QueueingDispatcher
25 */
26 public $dispatcher;
27
28 /**
29 * The job types that should be intercepted instead of dispatched.
30 *
31 * @var array
32 */
33 protected $jobsToFake = [];
34
35 /**
36 * The job types that should be dispatched instead of faked.
37 *
38 * @var array
39 */
40 protected $jobsToDispatch = [];
41
42 /**
43 * The fake repository to track batched jobs.
44 *
45 * @var \Illuminate\Bus\BatchRepository
46 */
47 protected $batchRepository;
48
49 /**
50 * The commands that have been dispatched.
51 *
52 * @var array
53 */
54 protected $commands = [];
55
56 /**
57 * The commands that have been dispatched synchronously.
58 *
59 * @var array
60 */
61 protected $commandsSync = [];
62
63 /**
64 * The commands that have been dispatched after the response has been sent.
65 *
66 * @var array
67 */
68 protected $commandsAfterResponse = [];
69
70 /**
71 * The batches that have been dispatched.
72 *
73 * @var array
74 */
75 protected $batches = [];
76
77 /**
78 * Indicates if commands should be serialized and restored when pushed to the Bus.
79 *
80 * @var bool
81 */
82 protected bool $serializeAndRestore = false;
83
84 /**
85 * Create a new bus fake instance.
86 *
87 * @param \Illuminate\Contracts\Bus\QueueingDispatcher $dispatcher
88 * @param array|string $jobsToFake
89 * @param \Illuminate\Bus\BatchRepository|null $batchRepository
90 */
91 public function __construct(QueueingDispatcher $dispatcher, $jobsToFake = [], ?BatchRepository $batchRepository = null)
92 {
93 $this->dispatcher = $dispatcher;
94 $this->jobsToFake = Arr::wrap($jobsToFake);
95 $this->batchRepository = $batchRepository ?: new BatchRepositoryFake;
96 }
97
98 /**
99 * Specify the jobs that should be dispatched instead of faked.
100 *
101 * @param array|string $jobsToDispatch
102 * @return $this
103 */
104 public function except($jobsToDispatch)
105 {
106 $this->jobsToDispatch = array_merge($this->jobsToDispatch, Arr::wrap($jobsToDispatch));
107
108 return $this;
109 }
110
111 /**
112 * Assert if a job was dispatched based on a truth-test callback.
113 *
114 * @param string|\Closure $command
115 * @param callable|int|null $callback
116 * @return void
117 */
118 public function assertDispatched($command, $callback = null)
119 {
120 if ($command instanceof Closure) {
121 [$command, $callback] = [$this->firstClosureParameterType($command), $command];
122 }
123
124 if (is_numeric($callback)) {
125 return $this->assertDispatchedTimes($command, $callback);
126 }
127
128 PHPUnit::assertTrue(
129 $this->dispatched($command, $callback)->count() > 0 ||
130 $this->dispatchedAfterResponse($command, $callback)->count() > 0 ||
131 $this->dispatchedSync($command, $callback)->count() > 0,
132 "The expected [{$command}] job was not dispatched."
133 );
134 }
135
136 /**
137 * Assert if a job was pushed exactly once.
138 *
139 * @param string|\Closure $command
140 * @return void
141 */
142 public function assertDispatchedOnce($command)
143 {
144 $this->assertDispatchedTimes($command, 1);
145 }
146
147 /**
148 * Assert if a job was pushed a number of times.
149 *
150 * @param string|\Closure $command
151 * @param int $times
152 * @return void
153 */
154 public function assertDispatchedTimes($command, $times = 1)
155 {
156 $callback = null;
157
158 if ($command instanceof Closure) {
159 [$command, $callback] = [$this->firstClosureParameterType($command), $command];
160 }
161
162 $count = $this->dispatched($command, $callback)->count() +
163 $this->dispatchedAfterResponse($command, $callback)->count() +
164 $this->dispatchedSync($command, $callback)->count();
165
166 PHPUnit::assertSame(
167 $times, $count,
168 sprintf(
169 "The expected [{$command}] job was pushed {$count} %s instead of {$times} %s.",
170 Str::plural('time', $count),
171 Str::plural('time', $times)
172 )
173 );
174 }
175
176 /**
177 * Determine if a job was dispatched based on a truth-test callback.
178 *
179 * @param string|\Closure $command
180 * @param callable|null $callback
181 * @return void
182 */
183 public function assertNotDispatched($command, $callback = null)
184 {
185 if ($command instanceof Closure) {
186 [$command, $callback] = [$this->firstClosureParameterType($command), $command];
187 }
188
189 PHPUnit::assertTrue(
190 $this->dispatched($command, $callback)->count() === 0 &&
191 $this->dispatchedAfterResponse($command, $callback)->count() === 0 &&
192 $this->dispatchedSync($command, $callback)->count() === 0,
193 "The unexpected [{$command}] job was dispatched."
194 );
195 }
196
197 /**
198 * Assert that no jobs were dispatched.
199 *
200 * @return void
201 */
202 public function assertNothingDispatched()
203 {
204 $commandNames = implode("\n- ", array_keys($this->commands));
205
206 PHPUnit::assertEmpty($this->commands, "The following jobs were dispatched unexpectedly:\n\n- $commandNames\n");
207 }
208
209 /**
210 * Assert if a job was explicitly dispatched synchronously based on a truth-test callback.
211 *
212 * @param string|\Closure $command
213 * @param callable|int|null $callback
214 * @return void
215 */
216 public function assertDispatchedSync($command, $callback = null)
217 {
218 if ($command instanceof Closure) {
219 [$command, $callback] = [$this->firstClosureParameterType($command), $command];
220 }
221
222 if (is_numeric($callback)) {
223 return $this->assertDispatchedSyncTimes($command, $callback);
224 }
225
226 PHPUnit::assertTrue(
227 $this->dispatchedSync($command, $callback)->count() > 0,
228 "The expected [{$command}] job was not dispatched synchronously."
229 );
230 }
231
232 /**
233 * Assert if a job was pushed synchronously a number of times.
234 *
235 * @param string|\Closure $command
236 * @param int $times
237 * @return void
238 */
239 public function assertDispatchedSyncTimes($command, $times = 1)
240 {
241 $callback = null;
242
243 if ($command instanceof Closure) {
244 [$command, $callback] = [$this->firstClosureParameterType($command), $command];
245 }
246
247 $count = $this->dispatchedSync($command, $callback)->count();
248
249 PHPUnit::assertSame(
250 $times, $count,
251 sprintf(
252 "The expected [{$command}] job was synchronously pushed {$count} %s instead of {$times} %s.",
253 Str::plural('time', $count),
254 Str::plural('time', $times)
255 )
256 );
257 }
258
259 /**
260 * Determine if a job was dispatched based on a truth-test callback.
261 *
262 * @param string|\Closure $command
263 * @param callable|null $callback
264 * @return void
265 */
266 public function assertNotDispatchedSync($command, $callback = null)
267 {
268 if ($command instanceof Closure) {
269 [$command, $callback] = [$this->firstClosureParameterType($command), $command];
270 }
271
272 PHPUnit::assertCount(
273 0, $this->dispatchedSync($command, $callback),
274 "The unexpected [{$command}] job was dispatched synchronously."
275 );
276 }
277
278 /**
279 * Assert if a job was dispatched after the response was sent based on a truth-test callback.
280 *
281 * @param string|\Closure $command
282 * @param callable|int|null $callback
283 * @return void
284 */
285 public function assertDispatchedAfterResponse($command, $callback = null)
286 {
287 if ($command instanceof Closure) {
288 [$command, $callback] = [$this->firstClosureParameterType($command), $command];
289 }
290
291 if (is_numeric($callback)) {
292 return $this->assertDispatchedAfterResponseTimes($command, $callback);
293 }
294
295 PHPUnit::assertTrue(
296 $this->dispatchedAfterResponse($command, $callback)->count() > 0,
297 "The expected [{$command}] job was not dispatched after sending the response."
298 );
299 }
300
301 /**
302 * Assert if a job was pushed after the response was sent a number of times.
303 *
304 * @param string|\Closure $command
305 * @param int $times
306 * @return void
307 */
308 public function assertDispatchedAfterResponseTimes($command, $times = 1)
309 {
310 $callback = null;
311
312 if ($command instanceof Closure) {
313 [$command, $callback] = [$this->firstClosureParameterType($command), $command];
314 }
315
316 $count = $this->dispatchedAfterResponse($command, $callback)->count();
317
318 PHPUnit::assertSame(
319 $times, $count,
320 sprintf(
321 "The expected [{$command}] job was pushed {$count} %s instead of {$times} %s.",
322 Str::plural('time', $count),
323 Str::plural('time', $times)
324 )
325 );
326 }
327
328 /**
329 * Determine if a job was dispatched based on a truth-test callback.
330 *
331 * @param string|\Closure $command
332 * @param callable|null $callback
333 * @return void
334 */
335 public function assertNotDispatchedAfterResponse($command, $callback = null)
336 {
337 if ($command instanceof Closure) {
338 [$command, $callback] = [$this->firstClosureParameterType($command), $command];
339 }
340
341 PHPUnit::assertCount(
342 0, $this->dispatchedAfterResponse($command, $callback),
343 "The unexpected [{$command}] job was dispatched after sending the response."
344 );
345 }
346
347 /**
348 * Assert if a chain of jobs was dispatched.
349 *
350 * @param array $expectedChain
351 * @return void
352 */
353 public function assertChained(array $expectedChain)
354 {
355 $command = $expectedChain[0];
356
357 $expectedChain = array_slice($expectedChain, 1);
358
359 $callback = null;
360
361 if ($command instanceof Closure) {
362 [$command, $callback] = [$this->firstClosureParameterType($command), $command];
363 } elseif ($command instanceof ChainedBatchTruthTest) {
364 $instance = $command;
365
366 $command = ChainedBatch::class;
367
368 $callback = fn ($job) => $instance($job->toPendingBatch());
369 } elseif (! is_string($command)) {
370 $instance = $command;
371
372 $command = get_class($instance);
373
374 $callback = function ($job) use ($instance) {
375 return serialize($this->resetChainPropertiesToDefaults($job)) === serialize($instance);
376 };
377 }
378
379 PHPUnit::assertTrue(
380 $this->dispatched($command, $callback)->isNotEmpty(),
381 "The expected [{$command}] job was not dispatched."
382 );
383
384 $this->assertDispatchedWithChainOfObjects($command, $expectedChain, $callback);
385 }
386
387 /**
388 * Assert no chained jobs was dispatched.
389 *
390 * @return void
391 */
392 public function assertNothingChained()
393 {
394 $this->assertNothingDispatched();
395 }
396
397 /**
398 * Reset the chain properties to their default values on the job.
399 *
400 * @param mixed $job
401 * @return mixed
402 */
403 protected function resetChainPropertiesToDefaults($job)
404 {
405 return tap(clone $job, function ($job) {
406 $job->chainConnection = null;
407 $job->chainQueue = null;
408 $job->chainCatchCallbacks = null;
409 $job->chained = [];
410 });
411 }
412
413 /**
414 * Assert if a job was dispatched with an empty chain based on a truth-test callback.
415 *
416 * @param string|\Closure $command
417 * @param callable|null $callback
418 * @return void
419 */
420 public function assertDispatchedWithoutChain($command, $callback = null)
421 {
422 if ($command instanceof Closure) {
423 [$command, $callback] = [$this->firstClosureParameterType($command), $command];
424 }
425
426 PHPUnit::assertTrue(
427 $this->dispatched($command, $callback)->isNotEmpty(),
428 "The expected [{$command}] job was not dispatched."
429 );
430
431 $this->assertDispatchedWithChainOfObjects($command, [], $callback);
432 }
433
434 /**
435 * Assert if a job was dispatched with chained jobs based on a truth-test callback.
436 *
437 * @param string $command
438 * @param array $expectedChain
439 * @param callable|null $callback
440 * @return void
441 */
442 protected function assertDispatchedWithChainOfObjects($command, $expectedChain, $callback)
443 {
444 $chain = $expectedChain;
445
446 PHPUnit::assertTrue(
447 $this->dispatched($command, $callback)->filter(function ($job) use ($chain) {
448 if (count($chain) !== count($job->chained)) {
449 return false;
450 }
451
452 foreach ($job->chained as $index => $serializedChainedJob) {
453 if ($chain[$index] instanceof ChainedBatchTruthTest) {
454 $chainedBatch = unserialize($serializedChainedJob);
455
456 if (! $chainedBatch instanceof ChainedBatch ||
457 ! $chain[$index]($chainedBatch->toPendingBatch())) {
458 return false;
459 }
460 } elseif ($chain[$index] instanceof Closure) {
461 [$expectedType, $callback] = [$this->firstClosureParameterType($chain[$index]), $chain[$index]];
462
463 $chainedJob = unserialize($serializedChainedJob);
464
465 if (! $chainedJob instanceof $expectedType) {
466 throw new RuntimeException('The chained job was expected to be of type '.$expectedType.', '.$chainedJob::class.' chained.');
467 }
468
469 if (! $callback($chainedJob)) {
470 return false;
471 }
472 } elseif (is_string($chain[$index])) {
473 if ($chain[$index] != get_class(unserialize($serializedChainedJob))) {
474 return false;
475 }
476 } elseif (serialize($chain[$index]) != $serializedChainedJob) {
477 return false;
478 }
479 }
480
481 return true;
482 })->isNotEmpty(),
483 'The expected chain was not dispatched.'
484 );
485 }
486
487 /**
488 * Create a new assertion about a chained batch.
489 *
490 * @param \Closure(\Illuminate\Bus\PendingBatch): bool $callback
491 * @return \Illuminate\Support\Testing\Fakes\ChainedBatchTruthTest
492 */
493 public function chainedBatch(Closure $callback)
494 {
495 return new ChainedBatchTruthTest($callback);
496 }
497
498 /**
499 * Assert if a batch was dispatched based on a truth-test callback.
500 *
501 * @param array|callable(\Illuminate\Bus\PendingBatch): bool $callback
502 * @return void
503 */
504 public function assertBatched(callable|array $callback)
505 {
506 $callback = is_array($callback) ? fn (PendingBatchFake $batch) => $batch->hasJobs($callback) : $callback;
507
508 PHPUnit::assertTrue(
509 $this->batched($callback)->count() > 0,
510 'The expected batch was not dispatched.'
511 );
512 }
513
514 /**
515 * Assert the number of batches that have been dispatched.
516 *
517 * @param int $count
518 * @return void
519 */
520 public function assertBatchCount($count)
521 {
522 PHPUnit::assertCount(
523 $count, $this->batches,
524 );
525 }
526
527 /**
528 * Assert that no batched jobs were dispatched.
529 *
530 * @return void
531 */
532 public function assertNothingBatched()
533 {
534 $jobNames = (new Collection($this->batches))
535 ->map(fn ($batch) => $batch->jobs->map(fn ($job) => get_class($job)))
536 ->flatten()
537 ->join("\n- ");
538
539 PHPUnit::assertEmpty($this->batches, "The following batched jobs were dispatched unexpectedly:\n\n- $jobNames\n");
540 }
541
542 /**
543 * Assert that no jobs were dispatched, chained, or batched.
544 *
545 * @return void
546 */
547 public function assertNothingPlaced()
548 {
549 $this->assertNothingDispatched();
550 $this->assertNothingBatched();
551 }
552
553 /**
554 * Get all of the jobs matching a truth-test callback.
555 *
556 * @param string $command
557 * @param callable|null $callback
558 * @return \Illuminate\Support\Collection
559 */
560 public function dispatched($command, $callback = null)
561 {
562 if (! $this->hasDispatched($command)) {
563 return new Collection;
564 }
565
566 $callback = $callback ?: fn () => true;
567
568 return (new Collection($this->commands[$command]))->filter(fn ($command) => $callback($command));
569 }
570
571 /**
572 * Get all of the jobs dispatched synchronously matching a truth-test callback.
573 *
574 * @param string $command
575 * @param callable|null $callback
576 * @return \Illuminate\Support\Collection
577 */
578 public function dispatchedSync(string $command, $callback = null)
579 {
580 if (! $this->hasDispatchedSync($command)) {
581 return new Collection;
582 }
583
584 $callback = $callback ?: fn () => true;
585
586 return (new Collection($this->commandsSync[$command]))->filter(fn ($command) => $callback($command));
587 }
588
589 /**
590 * Get all of the jobs dispatched after the response was sent matching a truth-test callback.
591 *
592 * @param string $command
593 * @param callable|null $callback
594 * @return \Illuminate\Support\Collection
595 */
596 public function dispatchedAfterResponse(string $command, $callback = null)
597 {
598 if (! $this->hasDispatchedAfterResponse($command)) {
599 return new Collection;
600 }
601
602 $callback = $callback ?: fn () => true;
603
604 return (new Collection($this->commandsAfterResponse[$command]))->filter(fn ($command) => $callback($command));
605 }
606
607 /**
608 * Get all of the pending batches matching a truth-test callback.
609 *
610 * @param callable(\Illuminate\Bus\PendingBatch): bool $callback
611 * @return \Illuminate\Support\Collection<int, \Illuminate\Bus\PendingBatch>
612 */
613 public function batched(callable $callback)
614 {
615 if (empty($this->batches)) {
616 return new Collection;
617 }
618
619 return (new Collection($this->batches))->filter(fn ($batch) => $callback($batch));
620 }
621
622 /**
623 * Determine if there are any stored commands for a given class.
624 *
625 * @param string $command
626 * @return bool
627 */
628 public function hasDispatched($command)
629 {
630 return isset($this->commands[$command]) && ! empty($this->commands[$command]);
631 }
632
633 /**
634 * Determine if there are any stored commands for a given class.
635 *
636 * @param string $command
637 * @return bool
638 */
639 public function hasDispatchedSync($command)
640 {
641 return isset($this->commandsSync[$command]) && ! empty($this->commandsSync[$command]);
642 }
643
644 /**
645 * Determine if there are any stored commands for a given class.
646 *
647 * @param string $command
648 * @return bool
649 */
650 public function hasDispatchedAfterResponse($command)
651 {
652 return isset($this->commandsAfterResponse[$command]) && ! empty($this->commandsAfterResponse[$command]);
653 }
654
655 /**
656 * Dispatch a command to its appropriate handler.
657 *
658 * @param mixed $command
659 * @return mixed
660 */
661 public function dispatch($command)
662 {
663 if ($this->shouldFakeJob($command)) {
664 $this->commands[get_class($command)][] = $this->getCommandRepresentation($command);
665 } else {
666 return $this->dispatcher->dispatch($command);
667 }
668 }
669
670 /**
671 * Dispatch a command to its appropriate handler in the current process.
672 *
673 * Queueable jobs will be dispatched to the "sync" queue.
674 *
675 * @param mixed $command
676 * @param mixed $handler
677 * @return mixed
678 */
679 public function dispatchSync($command, $handler = null)
680 {
681 if ($this->shouldFakeJob($command)) {
682 $this->commandsSync[get_class($command)][] = $this->getCommandRepresentation($command);
683 } else {
684 return $this->dispatcher->dispatchSync($command, $handler);
685 }
686 }
687
688 /**
689 * Dispatch a command to its appropriate handler in the current process.
690 *
691 * @param mixed $command
692 * @param mixed $handler
693 * @return mixed
694 */
695 public function dispatchNow($command, $handler = null)
696 {
697 if ($this->shouldFakeJob($command)) {
698 $this->commands[get_class($command)][] = $this->getCommandRepresentation($command);
699 } else {
700 return $this->dispatcher->dispatchNow($command, $handler);
701 }
702 }
703
704 /**
705 * Dispatch a command to its appropriate handler behind a queue.
706 *
707 * @param mixed $command
708 * @return mixed
709 */
710 public function dispatchToQueue($command)
711 {
712 if ($this->shouldFakeJob($command)) {
713 $this->commands[get_class($command)][] = $this->getCommandRepresentation($command);
714 } else {
715 return $this->dispatcher->dispatchToQueue($command);
716 }
717 }
718
719 /**
720 * Dispatch a command to its appropriate handler.
721 *
722 * @param mixed $command
723 * @return mixed
724 */
725 public function dispatchAfterResponse($command)
726 {
727 if ($this->shouldFakeJob($command)) {
728 $this->commandsAfterResponse[get_class($command)][] = $this->getCommandRepresentation($command);
729 } else {
730 return $this->dispatcher->dispatch($command);
731 }
732 }
733
734 /**
735 * Create a new chain of queueable jobs.
736 *
737 * @param \Illuminate\Support\Collection|array|null $jobs
738 * @return \Illuminate\Foundation\Bus\PendingChain
739 */
740 public function chain($jobs = null)
741 {
742 $jobs = Collection::wrap($jobs);
743 $jobs = ChainedBatch::prepareNestedBatches($jobs);
744
745 return new PendingChainFake($this, $jobs->shift(), $jobs->toArray());
746 }
747
748 /**
749 * Attempt to find the batch with the given ID.
750 *
751 * @param string $batchId
752 * @return \Illuminate\Bus\Batch|null
753 */
754 public function findBatch(string $batchId)
755 {
756 return $this->batchRepository->find($batchId);
757 }
758
759 /**
760 * Create a new batch of queueable jobs.
761 *
762 * @param \Illuminate\Support\Collection|array $jobs
763 * @return \Illuminate\Bus\PendingBatch
764 */
765 public function batch($jobs)
766 {
767 return new PendingBatchFake($this, Collection::wrap($jobs));
768 }
769
770 /**
771 * Dispatch an empty job batch for testing.
772 *
773 * @param string $name
774 * @return \Illuminate\Bus\Batch
775 */
776 public function dispatchFakeBatch($name = '')
777 {
778 return $this->batch([])->name($name)->dispatch();
779 }
780
781 /**
782 * Record the fake pending batch dispatch.
783 *
784 * @param \Illuminate\Bus\PendingBatch $pendingBatch
785 * @return \Illuminate\Bus\Batch
786 */
787 public function recordPendingBatch(PendingBatch $pendingBatch)
788 {
789 $this->batches[] = $pendingBatch;
790
791 return $this->batchRepository->store($pendingBatch);
792 }
793
794 /**
795 * Determine if a command should be faked or actually dispatched.
796 *
797 * @param mixed $command
798 * @return bool
799 */
800 protected function shouldFakeJob($command)
801 {
802 if ($this->shouldDispatchCommand($command)) {
803 return false;
804 }
805
806 if (empty($this->jobsToFake)) {
807 return true;
808 }
809
810 return (new Collection($this->jobsToFake))
811 ->filter(function ($job) use ($command) {
812 return $job instanceof Closure
813 ? $job($command)
814 : $job === get_class($command);
815 })->isNotEmpty();
816 }
817
818 /**
819 * Determine if a command should be dispatched or not.
820 *
821 * @param mixed $command
822 * @return bool
823 */
824 protected function shouldDispatchCommand($command)
825 {
826 return (new Collection($this->jobsToDispatch))
827 ->filter(function ($job) use ($command) {
828 return $job instanceof Closure
829 ? $job($command)
830 : $job === get_class($command);
831 })->isNotEmpty();
832 }
833
834 /**
835 * Specify if commands should be serialized and restored when being batched.
836 *
837 * @param bool $serializeAndRestore
838 * @return $this
839 */
840 public function serializeAndRestore(bool $serializeAndRestore = true)
841 {
842 $this->serializeAndRestore = $serializeAndRestore;
843
844 return $this;
845 }
846
847 /**
848 * Serialize and unserialize the command to simulate the queueing process.
849 *
850 * @param mixed $command
851 * @return mixed
852 */
853 protected function serializeAndRestoreCommand($command)
854 {
855 return unserialize(serialize($command));
856 }
857
858 /**
859 * Return the command representation that should be stored.
860 *
861 * @param mixed $command
862 * @return mixed
863 */
864 protected function getCommandRepresentation($command)
865 {
866 return $this->serializeAndRestore ? $this->serializeAndRestoreCommand($command) : $command;
867 }
868
869 /**
870 * Set the pipes commands should be piped through before dispatching.
871 *
872 * @param array $pipes
873 * @return $this
874 */
875 public function pipeThrough(array $pipes)
876 {
877 $this->dispatcher->pipeThrough($pipes);
878
879 return $this;
880 }
881
882 /**
883 * Determine if the given command has a handler.
884 *
885 * @param mixed $command
886 * @return bool
887 */
888 public function hasCommandHandler($command)
889 {
890 return $this->dispatcher->hasCommandHandler($command);
891 }
892
893 /**
894 * Retrieve the handler for a command.
895 *
896 * @param mixed $command
897 * @return mixed
898 */
899 public function getCommandHandler($command)
900 {
901 return $this->dispatcher->getCommandHandler($command);
902 }
903
904 /**
905 * Map a command to a handler.
906 *
907 * @param array $map
908 * @return $this
909 */
910 public function map(array $map)
911 {
912 $this->dispatcher->map($map);
913
914 return $this;
915 }
916
917 /**
918 * Get the batches that have been dispatched.
919 *
920 * @return array
921 */
922 public function dispatchedBatches()
923 {
924 return $this->batches;
925 }
926 }