12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace Test\BackgroundJob;
- use OCP\AppFramework\Utility\ITimeFactory;
- use OCP\ILogger;
- class JobTest extends \Test\TestCase {
- private $run = false;
- private ITimeFactory $timeFactory;
- protected function setUp(): void {
- parent::setUp();
- $this->run = false;
- $this->timeFactory = \OC::$server->get(ITimeFactory::class);
- }
- public function testRemoveAfterException() {
- $jobList = new DummyJobList();
- $e = new \Exception();
- $job = new TestJob($this->timeFactory, $this, function () use ($e) {
- throw $e;
- });
- $jobList->add($job);
- $logger = $this->getMockBuilder(ILogger::class)
- ->disableOriginalConstructor()
- ->getMock();
- $logger->expects($this->once())
- ->method('error');
- $this->assertCount(1, $jobList->getAll());
- $job->execute($jobList, $logger);
- $this->assertTrue($this->run);
- $this->assertCount(1, $jobList->getAll());
- }
- public function testRemoveAfterError() {
- $jobList = new DummyJobList();
- $job = new TestJob($this->timeFactory, $this, function () {
- $test = null;
- $test->someMethod();
- });
- $jobList->add($job);
- $logger = $this->getMockBuilder(ILogger::class)
- ->disableOriginalConstructor()
- ->getMock();
- $logger->expects($this->once())
- ->method('error');
- $this->assertCount(1, $jobList->getAll());
- $job->execute($jobList, $logger);
- $this->assertTrue($this->run);
- $this->assertCount(1, $jobList->getAll());
- }
- public function markRun() {
- $this->run = true;
- }
- }
|