Debian Codegraph @

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

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