QueuedJobTest.php 892 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\BackgroundJob;
  8. use OCP\AppFramework\Utility\ITimeFactory;
  9. use OCP\BackgroundJob\QueuedJob;
  10. class TestQueuedJobNew extends QueuedJob {
  11. public bool $ran = false;
  12. public function run($argument) {
  13. $this->ran = true;
  14. }
  15. }
  16. class QueuedJobTest extends \Test\TestCase {
  17. private DummyJobList $jobList;
  18. protected function setUp(): void {
  19. parent::setUp();
  20. $this->jobList = new DummyJobList();
  21. }
  22. public function testJobShouldBeRemovedNew() {
  23. $job = new TestQueuedJobNew(\OCP\Server::get(ITimeFactory::class));
  24. $job->setId(42);
  25. $this->jobList->add($job);
  26. $this->assertTrue($this->jobList->has($job, null));
  27. $job->start($this->jobList);
  28. $this->assertTrue($job->ran);
  29. }
  30. }