Skip to content

Commit 85b9552

Browse files
committed
test: update DummyJobList
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 1a9f7d5 commit 85b9552

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

tests/lib/BackgroundJob/DummyJobList.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
2626
private array $reserved = [];
2727

2828
private int $last = 0;
29+
private int $lastId = 0;
2930

3031
public function __construct() {
3132
}
@@ -40,6 +41,8 @@ public function add($job, $argument = null, ?int $firstCheck = null): void {
4041
$job = \OCP\Server::get($job);
4142
}
4243
$job->setArgument($argument);
44+
$job->setId($this->lastId);
45+
$this->lastId++;
4346
if (!$this->has($job, null)) {
4447
$this->jobs[] = $job;
4548
}
@@ -54,9 +57,20 @@ public function scheduleAfter(string $job, int $runAfter, $argument = null): voi
5457
* @param mixed $argument
5558
*/
5659
public function remove($job, $argument = null): void {
57-
$index = array_search($job, $this->jobs);
58-
if ($index !== false) {
59-
unset($this->jobs[$index]);
60+
foreach ($this->jobs as $index => $listJob) {
61+
if (get_class($job) === get_class($listJob) && $job->getArgument() == $listJob->getArgument()) {
62+
unset($this->jobs[$index]);
63+
return;
64+
}
65+
}
66+
}
67+
68+
public function removeById(int $id): void {
69+
foreach ($this->jobs as $index => $listJob) {
70+
if ($listJob->getId() === $id) {
71+
unset($this->jobs[$index]);
72+
return;
73+
}
6074
}
6175
}
6276

@@ -126,7 +140,7 @@ public function setLastJob(IJob $job): void {
126140
}
127141
}
128142

129-
public function getById(int $id): IJob {
143+
public function getById(int $id): ?IJob {
130144
foreach ($this->jobs as $job) {
131145
if ($job->getId() === $id) {
132146
return $job;

0 commit comments

Comments
 (0)