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