JobTest.php 957 B

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