use logException() to properly log the exception

This commit is contained in:
Morris Jobke 2016-01-14 10:38:53 +01:00
parent 64c8427d81
commit 86f08f59d6
2 changed files with 9 additions and 4 deletions

View file

@ -52,7 +52,8 @@ abstract class Job implements IJob {
$this->run($this->argument);
} catch (\Exception $e) {
if ($logger) {
$logger->error('Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . '): ' . $e->getMessage());
$logger->error('Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')');
$logger->logException($e);
}
}
}

View file

@ -18,8 +18,9 @@ class Job extends \Test\TestCase {
public function testRemoveAfterException() {
$jobList = new DummyJobList();
$job = new TestJob($this, function () {
throw new \Exception();
$e = new \Exception();
$job = new TestJob($this, function () use ($e) {
throw $e;
});
$jobList->add($job);
@ -28,7 +29,10 @@ class Job extends \Test\TestCase {
->getMock();
$logger->expects($this->once())
->method('error')
->with('Error while running background job (class: Test\BackgroundJob\TestJob, arguments: ): ');
->with('Error while running background job (class: Test\BackgroundJob\TestJob, arguments: )');
$logger->expects($this->once())
->method('logException')
->with($e);
$this->assertCount(1, $jobList->getAll());
$job->execute($jobList, $logger);