|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Illuminate\Support\Testing\Fakes; |
| 4 | + |
| 5 | +use Carbon\CarbonImmutable; |
| 6 | +use Illuminate\Bus\Batch; |
| 7 | +use Illuminate\Support\Carbon; |
| 8 | + |
| 9 | +class BatchFake extends Batch |
| 10 | +{ |
| 11 | + /** |
| 12 | + * The jobs that have been added to the batch. |
| 13 | + * |
| 14 | + * @var array |
| 15 | + */ |
| 16 | + public $added = []; |
| 17 | + |
| 18 | + /** |
| 19 | + * Indicates if the batch has been deleted. |
| 20 | + * |
| 21 | + * @var bool |
| 22 | + */ |
| 23 | + public $deleted = false; |
| 24 | + |
| 25 | + /** |
| 26 | + * Create a new batch instance. |
| 27 | + * |
| 28 | + * @param string $id |
| 29 | + * @param string $name |
| 30 | + * @param int $totalJobs |
| 31 | + * @param int $pendingJobs |
| 32 | + * @param int $failedJobs |
| 33 | + * @param array $failedJobIds |
| 34 | + * @param array $options |
| 35 | + * @param \Carbon\CarbonImmutable $createdAt |
| 36 | + * @param \Carbon\CarbonImmutable|null $cancelledAt |
| 37 | + * @param \Carbon\CarbonImmutable|null $finishedAt |
| 38 | + * @return void |
| 39 | + */ |
| 40 | + public function __construct(string $id, |
| 41 | + string $name, |
| 42 | + int $totalJobs, |
| 43 | + int $pendingJobs, |
| 44 | + int $failedJobs, |
| 45 | + array $failedJobIds, |
| 46 | + array $options, |
| 47 | + CarbonImmutable $createdAt, |
| 48 | + ?CarbonImmutable $cancelledAt = null, |
| 49 | + ?CarbonImmutable $finishedAt = null) |
| 50 | + { |
| 51 | + $this->id = $id; |
| 52 | + $this->name = $name; |
| 53 | + $this->totalJobs = $totalJobs; |
| 54 | + $this->pendingJobs = $pendingJobs; |
| 55 | + $this->failedJobs = $failedJobs; |
| 56 | + $this->failedJobIds = $failedJobIds; |
| 57 | + $this->options = $options; |
| 58 | + $this->createdAt = $createdAt; |
| 59 | + $this->cancelledAt = $cancelledAt; |
| 60 | + $this->finishedAt = $finishedAt; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Get a fresh instance of the batch represented by this ID. |
| 65 | + * |
| 66 | + * @return self |
| 67 | + */ |
| 68 | + public function fresh() |
| 69 | + { |
| 70 | + return $this; |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Add additional jobs to the batch. |
| 75 | + * |
| 76 | + * @param \Illuminate\Support\Enumerable|object|array $jobs |
| 77 | + * @return self |
| 78 | + */ |
| 79 | + public function add($jobs) |
| 80 | + { |
| 81 | + $this->added[] = array_merge($this->added, $jobs); |
| 82 | + |
| 83 | + return $this; |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Record that a job within the batch finished successfully, executing any callbacks if necessary. |
| 88 | + * |
| 89 | + * @param string $jobId |
| 90 | + * @return void |
| 91 | + */ |
| 92 | + public function recordSuccessfulJob(string $jobId) |
| 93 | + { |
| 94 | + // |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Decrement the pending jobs for the batch. |
| 99 | + * |
| 100 | + * @param string $jobId |
| 101 | + * @return \Illuminate\Bus\UpdatedBatchJobCounts |
| 102 | + */ |
| 103 | + public function decrementPendingJobs(string $jobId) |
| 104 | + { |
| 105 | + // |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Record that a job within the batch failed to finish successfully, executing any callbacks if necessary. |
| 110 | + * |
| 111 | + * @param string $jobId |
| 112 | + * @param \Throwable $e |
| 113 | + * @return void |
| 114 | + */ |
| 115 | + public function recordFailedJob(string $jobId, $e) |
| 116 | + { |
| 117 | + // |
| 118 | + } |
| 119 | + |
| 120 | + /** |
| 121 | + * Increment the failed jobs for the batch. |
| 122 | + * |
| 123 | + * @param string $jobId |
| 124 | + * @return \Illuminate\Bus\UpdatedBatchJobCounts |
| 125 | + */ |
| 126 | + public function incrementFailedJobs(string $jobId) |
| 127 | + { |
| 128 | + return new UpdatedBatchJobCounts; |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Cancel the batch. |
| 133 | + * |
| 134 | + * @return void |
| 135 | + */ |
| 136 | + public function cancel() |
| 137 | + { |
| 138 | + $this->cancelledAt = Carbon::now(); |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * Delete the batch from storage. |
| 143 | + * |
| 144 | + * @return void |
| 145 | + */ |
| 146 | + public function delete() |
| 147 | + { |
| 148 | + $this->deleted = true; |
| 149 | + } |
| 150 | + |
| 151 | + /** |
| 152 | + * Determine if the batch has been deleted. |
| 153 | + * |
| 154 | + * @return bool |
| 155 | + */ |
| 156 | + public function deleted() |
| 157 | + { |
| 158 | + return $this->deleted; |
| 159 | + } |
| 160 | +} |
0 commit comments