Skip to content

Commit 75e26b1

Browse files
icewind1991backportbot[bot]
authored andcommitted
test: update DummyJobList
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent e52146b commit 75e26b1

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

tests/lib/BackgroundJob/DummyJobList.php

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

2929
private int $last = 0;
30+
private int $lastId = 0;
3031

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

@@ -127,7 +141,7 @@ public function setLastJob(IJob $job): void {
127141
}
128142
}
129143

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

0 commit comments

Comments
 (0)