0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-02-12 03:59:16 +00:00
nextcloud_server/tests/lib/BackgroundJob/TimedJobTest.php
Christoph Wurst 49dd79eabb
refactor: Add void return type to PHPUnit test methods
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2024-09-15 22:32:31 +02:00

69 lines
1.6 KiB
PHP

<?php
/**
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\BackgroundJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
class TestTimedJobNew extends TimedJob {
public bool $ran = false;
public function __construct(ITimeFactory $timeFactory) {
parent::__construct($timeFactory);
$this->setInterval(10);
}
public function run($argument) {
$this->ran = true;
}
}
class TimedJobTest extends \Test\TestCase {
private DummyJobList $jobList;
private ITimeFactory $time;
protected function setUp(): void {
parent::setUp();
$this->jobList = new DummyJobList();
$this->time = \OCP\Server::get(ITimeFactory::class);
}
public function testShouldRunAfterIntervalNew(): void {
$job = new TestTimedJobNew($this->time);
$job->setId(42);
$this->jobList->add($job);
$job->setLastRun(time() - 12);
$job->start($this->jobList);
$this->assertTrue($job->ran);
}
public function testShouldNotRunWithinIntervalNew(): void {
$job = new TestTimedJobNew($this->time);
$job->setId(42);
$this->jobList->add($job);
$job->setLastRun(time() - 5);
$job->start($this->jobList);
$this->assertFalse($job->ran);
}
public function testShouldNotTwiceNew(): void {
$job = new TestTimedJobNew($this->time);
$job->setId(42);
$this->jobList->add($job);
$job->setLastRun(time() - 15);
$job->start($this->jobList);
$this->assertTrue($job->ran);
$job->ran = false;
$job->start($this->jobList);
$this->assertFalse($job->ran);
}
}