Debian Codegraph @

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

raw symbols SCIP
1 <?php
2
3 namespace Illuminate\Support\Testing\Fakes;
4
5 use Closure;
6 use Illuminate\Bus\PendingBatch;
7 use Illuminate\Support\Collection;
8 use Illuminate\Support\Traits\ReflectsClosures;
9
10 class PendingBatchFake extends PendingBatch
11 {
12 use ReflectsClosures;
13
14 /**
15 * The fake bus instance.
16 *
17 * @var \Illuminate\Support\Testing\Fakes\BusFake
18 */
19 protected $bus;
20
21 /**
22 * Create a new pending batch instance.
23 *
24 * @param \Illuminate\Support\Testing\Fakes\BusFake $bus
25 * @param \Illuminate\Support\Collection $jobs
26 */
27 public function __construct(BusFake $bus, Collection $jobs)
28 {
29 $this->bus = $bus;
30 $this->jobs = $jobs->filter()->values();
31 }
32
33 /**
34 * Dispatch the batch.
35 *
36 * @return \Illuminate\Bus\Batch
37 */
38 public function dispatch()
39 {
40 return $this->bus->recordPendingBatch($this);
41 }
42
43 /**
44 * Dispatch the batch after the response is sent to the browser.
45 *
46 * @return \Illuminate\Bus\Batch
47 */
48 public function dispatchAfterResponse()
49 {
50 return $this->bus->recordPendingBatch($this);
51 }
52
53 /**
54 * Determine if the jobs in the batch match the given jobs.
55 *
56 * @param array $expectedJobs
57 * @return bool
58 */
59 public function hasJobs(array $expectedJobs)
60 {
61 if (count($this->jobs) !== count($expectedJobs)) {
62 return false;
63 }
64
65 foreach ($expectedJobs as $index => $expectedJob) {
66 if ($expectedJob instanceof Closure) {
67 $expectedType = $this->firstClosureParameterType($expectedJob);
68
69 if (! $this->jobs[$index] instanceof $expectedType) {
70 return false;
71 }
72
73 if (! $expectedJob($this->jobs[$index])) {
74 return false;
75 }
76 } elseif (is_string($expectedJob)) {
77 if ($expectedJob != get_class($this->jobs[$index])) {
78 return false;
79 }
80 } elseif (serialize($expectedJob) != serialize($this->jobs[$index])) {
81 return false;
82 }
83 }
84
85 return true;
86 }
87 }