diff options
Diffstat (limited to 'tests/lib/BackgroundJob/TimedJobTest.php')
-rw-r--r-- | tests/lib/BackgroundJob/TimedJobTest.php | 67 |
1 files changed, 10 insertions, 57 deletions
diff --git a/tests/lib/BackgroundJob/TimedJobTest.php b/tests/lib/BackgroundJob/TimedJobTest.php index 12f1c43adde..d0dd794a77c 100644 --- a/tests/lib/BackgroundJob/TimedJobTest.php +++ b/tests/lib/BackgroundJob/TimedJobTest.php @@ -9,23 +9,10 @@ namespace Test\BackgroundJob; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\TimedJob; -class TestTimedJob extends \OC\BackgroundJob\TimedJob { - /** @var bool */ - public $ran = false; - - public function __construct() { - $this->setInterval(10); - } - - public function run($argument) { - $this->ran = true; - } -} - -class TestTimedJobNew extends \OCP\BackgroundJob\TimedJob { - /** @var bool */ - public $ran = false; +class TestTimedJobNew extends TimedJob { + public bool $ran = false; public function __construct(ITimeFactory $timeFactory) { parent::__construct($timeFactory); @@ -38,57 +25,23 @@ class TestTimedJobNew extends \OCP\BackgroundJob\TimedJob { } class TimedJobTest extends \Test\TestCase { - /** @var DummyJobList $jobList */ - private $jobList; - - /** @var ITimeFactory */ - private $time; + private DummyJobList $jobList; + private ITimeFactory $time; protected function setUp(): void { parent::setUp(); $this->jobList = new DummyJobList(); - $this->time = \OC::$server->query(ITimeFactory::class); - } - - public function testShouldRunAfterInterval() { - $job = new TestTimedJob(); - $this->jobList->add($job); - - $job->setLastRun(time() - 12); - $job->execute($this->jobList); - $this->assertTrue($job->ran); + $this->time = \OCP\Server::get(ITimeFactory::class); } - public function testShouldNotRunWithinInterval() { - $job = new TestTimedJob(); - $this->jobList->add($job); - - $job->setLastRun(time() - 5); - $job->execute($this->jobList); - $this->assertFalse($job->ran); - } - - public function testShouldNotTwice() { - $job = new TestTimedJob(); - $this->jobList->add($job); - - $job->setLastRun(time() - 15); - $job->execute($this->jobList); - $this->assertTrue($job->ran); - $job->ran = false; - $job->execute($this->jobList); - $this->assertFalse($job->ran); - } - - public function testShouldRunAfterIntervalNew() { $job = new TestTimedJobNew($this->time); $job->setId(42); $this->jobList->add($job); $job->setLastRun(time() - 12); - $job->execute($this->jobList); + $job->start($this->jobList); $this->assertTrue($job->ran); } @@ -98,7 +51,7 @@ class TimedJobTest extends \Test\TestCase { $this->jobList->add($job); $job->setLastRun(time() - 5); - $job->execute($this->jobList); + $job->start($this->jobList); $this->assertFalse($job->ran); } @@ -108,10 +61,10 @@ class TimedJobTest extends \Test\TestCase { $this->jobList->add($job); $job->setLastRun(time() - 15); - $job->execute($this->jobList); + $job->start($this->jobList); $this->assertTrue($job->ran); $job->ran = false; - $job->execute($this->jobList); + $job->start($this->jobList); $this->assertFalse($job->ran); } } |