JobTest.php 976 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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\ILogger;
  10. class JobTest extends \Test\TestCase {
  11. private $run = false;
  12. protected function setUp() {
  13. parent::setUp();
  14. $this->run = false;
  15. }
  16. public function testRemoveAfterException() {
  17. $jobList = new DummyJobList();
  18. $e = new \Exception();
  19. $job = new TestJob($this, function () use ($e) {
  20. throw $e;
  21. });
  22. $jobList->add($job);
  23. $logger = $this->getMockBuilder(ILogger::class)
  24. ->disableOriginalConstructor()
  25. ->getMock();
  26. $logger->expects($this->once())
  27. ->method('logException')
  28. ->with($e);
  29. $this->assertCount(1, $jobList->getAll());
  30. $job->execute($jobList, $logger);
  31. $this->assertTrue($this->run);
  32. $this->assertCount(1, $jobList->getAll());
  33. }
  34. public function markRun() {
  35. $this->run = true;
  36. }
  37. }