| 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 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
protected $bus; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public function __construct(BusFake $bus, Collection $jobs) |
| 28 |
{ |
| 29 |
$this->bus = $bus; |
| 30 |
$this->jobs = $jobs->filter()->values(); |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public function dispatch() |
| 39 |
{ |
| 40 |
return $this->bus->recordPendingBatch($this); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public function dispatchAfterResponse() |
| 49 |
{ |
| 50 |
return $this->bus->recordPendingBatch($this); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 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 |
} |