1
0

QueuedJobTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\BackgroundJob;
  9. use OCP\AppFramework\Utility\ITimeFactory;
  10. class TestQueuedJob extends \OC\BackgroundJob\QueuedJob {
  11. public $ran = false;
  12. public function run($argument) {
  13. $this->ran = true;
  14. }
  15. }
  16. class TestQueuedJobNew extends \OCP\BackgroundJob\QueuedJob {
  17. public $ran = false;
  18. public function run($argument) {
  19. $this->ran = true;
  20. }
  21. }
  22. class QueuedJobTest extends \Test\TestCase {
  23. /**
  24. * @var DummyJobList $jobList
  25. */
  26. private $jobList;
  27. protected function setUp(): void {
  28. parent::setUp();
  29. $this->jobList = new DummyJobList();
  30. }
  31. public function testJobShouldBeRemoved() {
  32. $job = new TestQueuedJob();
  33. $this->jobList->add($job);
  34. $this->assertTrue($this->jobList->has($job, null));
  35. $job->execute($this->jobList);
  36. $this->assertTrue($job->ran);
  37. }
  38. public function testJobShouldBeRemovedNew() {
  39. $job = new TestQueuedJobNew(\OC::$server->query(ITimeFactory::class));
  40. $job->setId(42);
  41. $this->jobList->add($job);
  42. $this->assertTrue($this->jobList->has($job, null));
  43. $job->execute($this->jobList);
  44. $this->assertTrue($job->ran);
  45. }
  46. }