| 1 |
<?php |
| 2 |
|
| 3 |
namespace Illuminate\Support\Testing\Fakes; |
| 4 |
|
| 5 |
use Carbon\CarbonImmutable; |
| 6 |
use Closure; |
| 7 |
use Illuminate\Bus\BatchRepository; |
| 8 |
use Illuminate\Bus\PendingBatch; |
| 9 |
use Illuminate\Bus\UpdatedBatchJobCounts; |
| 10 |
use Illuminate\Support\Str; |
| 11 |
|
| 12 |
class BatchRepositoryFake implements BatchRepository |
| 13 |
{ |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
protected $batches = []; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public function get($limit, $before) |
| 29 |
{ |
| 30 |
return $this->batches; |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public function find(string $batchId) |
| 40 |
{ |
| 41 |
return $this->batches[$batchId] ?? null; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public function store(PendingBatch $batch) |
| 51 |
{ |
| 52 |
$id = (string) Str::orderedUuid(); |
| 53 |
|
| 54 |
$this->batches[$id] = new BatchFake( |
| 55 |
$id, |
| 56 |
$batch->name, |
| 57 |
count($batch->jobs), |
| 58 |
count($batch->jobs), |
| 59 |
0, |
| 60 |
[], |
| 61 |
$batch->options, |
| 62 |
CarbonImmutable::now(), |
| 63 |
null, |
| 64 |
null |
| 65 |
); |
| 66 |
|
| 67 |
return $this->batches[$id]; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
public function incrementTotalJobs(string $batchId, int $amount) |
| 78 |
{ |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public function decrementPendingJobs(string $batchId, string $jobId) |
| 90 |
{ |
| 91 |
return new UpdatedBatchJobCounts; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public function incrementFailedJobs(string $batchId, string $jobId) |
| 102 |
{ |
| 103 |
return new UpdatedBatchJobCounts; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
public function markAsFinished(string $batchId) |
| 113 |
{ |
| 114 |
if (isset($this->batches[$batchId])) { |
| 115 |
$this->batches[$batchId]->finishedAt = now(); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
public function cancel(string $batchId) |
| 126 |
{ |
| 127 |
if (isset($this->batches[$batchId])) { |
| 128 |
$this->batches[$batchId]->cancel(); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
public function delete(string $batchId) |
| 139 |
{ |
| 140 |
unset($this->batches[$batchId]); |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
public function transaction(Closure $callback) |
| 150 |
{ |
| 151 |
return $callback(); |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
public function rollBack() |
| 160 |
{ |
| 161 |
|
| 162 |
} |
| 163 |
} |