Debian Codegraph @

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

raw symbols SCIP
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 * The batches stored in the repository.
16 *
17 * @var \Illuminate\Bus\Batch[]
18 */
19 protected $batches = [];
20
21 /**
22 * Retrieve a list of batches.
23 *
24 * @param int $limit
25 * @param mixed $before
26 * @return \Illuminate\Bus\Batch[]
27 */
28 public function get($limit, $before)
29 {
30 return $this->batches;
31 }
32
33 /**
34 * Retrieve information about an existing batch.
35 *
36 * @param string $batchId
37 * @return \Illuminate\Bus\Batch|null
38 */
39 public function find(string $batchId)
40 {
41 return $this->batches[$batchId] ?? null;
42 }
43
44 /**
45 * Store a new pending batch.
46 *
47 * @param \Illuminate\Bus\PendingBatch $batch
48 * @return \Illuminate\Bus\Batch
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 * Increment the total number of jobs within the batch.
72 *
73 * @param string $batchId
74 * @param int $amount
75 * @return void
76 */
77 public function incrementTotalJobs(string $batchId, int $amount)
78 {
79 //
80 }
81
82 /**
83 * Decrement the total number of pending jobs for the batch.
84 *
85 * @param string $batchId
86 * @param string $jobId
87 * @return \Illuminate\Bus\UpdatedBatchJobCounts
88 */
89 public function decrementPendingJobs(string $batchId, string $jobId)
90 {
91 return new UpdatedBatchJobCounts;
92 }
93
94 /**
95 * Increment the total number of failed jobs for the batch.
96 *
97 * @param string $batchId
98 * @param string $jobId
99 * @return \Illuminate\Bus\UpdatedBatchJobCounts
100 */
101 public function incrementFailedJobs(string $batchId, string $jobId)
102 {
103 return new UpdatedBatchJobCounts;
104 }
105
106 /**
107 * Mark the batch that has the given ID as finished.
108 *
109 * @param string $batchId
110 * @return void
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 * Cancel the batch that has the given ID.
121 *
122 * @param string $batchId
123 * @return void
124 */
125 public function cancel(string $batchId)
126 {
127 if (isset($this->batches[$batchId])) {
128 $this->batches[$batchId]->cancel();
129 }
130 }
131
132 /**
133 * Delete the batch that has the given ID.
134 *
135 * @param string $batchId
136 * @return void
137 */
138 public function delete(string $batchId)
139 {
140 unset($this->batches[$batchId]);
141 }
142
143 /**
144 * Execute the given Closure within a storage specific transaction.
145 *
146 * @param \Closure $callback
147 * @return mixed
148 */
149 public function transaction(Closure $callback)
150 {
151 return $callback();
152 }
153
154 /**
155 * Rollback the last database transaction for the connection.
156 *
157 * @return void
158 */
159 public function rollBack()
160 {
161 //
162 }
163 }