Skip to content

Commit

Permalink
test: update DummyJobList
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed May 30, 2024
1 parent 1a9f7d5 commit 85b9552
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions tests/lib/BackgroundJob/DummyJobList.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
private array $reserved = [];

private int $last = 0;
private int $lastId = 0;

public function __construct() {
}
Expand All @@ -40,6 +41,8 @@ public function add($job, $argument = null, ?int $firstCheck = null): void {
$job = \OCP\Server::get($job);
}
$job->setArgument($argument);
$job->setId($this->lastId);
$this->lastId++;
if (!$this->has($job, null)) {
$this->jobs[] = $job;
}
Expand All @@ -54,9 +57,20 @@ public function scheduleAfter(string $job, int $runAfter, $argument = null): voi
* @param mixed $argument
*/
public function remove($job, $argument = null): void {
$index = array_search($job, $this->jobs);
if ($index !== false) {
unset($this->jobs[$index]);
foreach ($this->jobs as $index => $listJob) {
if (get_class($job) === get_class($listJob) && $job->getArgument() == $listJob->getArgument()) {
unset($this->jobs[$index]);
return;
}
}
}

public function removeById(int $id): void {
foreach ($this->jobs as $index => $listJob) {
if ($listJob->getId() === $id) {
unset($this->jobs[$index]);
return;
}
}
}

Expand Down Expand Up @@ -126,7 +140,7 @@ public function setLastJob(IJob $job): void {
}
}

public function getById(int $id): IJob {
public function getById(int $id): ?IJob {
foreach ($this->jobs as $job) {
if ($job->getId() === $id) {
return $job;
Expand Down

0 comments on commit 85b9552

Please sign in to comment.