/** * Print error information. * * @param \phpbu\App\Result $result */ protected function printErrors(Result $result) { /* @var $e \Exception */ foreach ($result->getErrors() as $e) { $this->write(sprintf("Exception '%s' with message '%s'\nin %s:%d\n\n", get_class($e), $e->getMessage(), $e->getFile(), $e->getLine())); } }
/** * Get error information. * * @param \phpbu\App\Result $result * @return string */ protected function getErrorHtml(Result $result) { $html = ''; $errors = $result->getErrors(); if (count($errors)) { $html .= '<table ' . TPL::getSnippet('sTableError') . '>'; /* @var $e Exception */ foreach ($errors as $e) { $html .= '<tr><td ' . TPL::getSnippet('sTableErrorCol') . '>' . sprintf("Exception '%s' with message '%s' in %s:%d", get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()) . '</td></tr>'; } $html .= '</table>'; } return $html; }
/** * Get error information. * * @param \phpbu\App\Result $result * @return array */ protected function extractErrors(Result $result) { $errors = []; /** @var \Exception $e */ foreach ($result->getErrors() as $e) { $errors[] = ['class' => get_class($e), 'msg' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]; } return $errors; }
/** * Tests Check failed. */ public function testBackupFailedOnFailedCheck() { $conf = new Configuration('/tmp/foo.xml'); $backup = new Configuration\Backup('test-backup', false); $check = new Configuration\Backup\Check('sizemin', '10M'); $result = new Result(); $result->phpbuStart($conf); $result->backupStart($backup); $result->backupEnd($backup); $result->checkStart($check); $result->addError(new Exception('failed')); $result->checkFailed($check); $result->backupFailed($backup); $result->backupEnd($backup); $result->phpbuEnd(); $this->assertFalse($result->wasSuccessful(), 'should be successful'); $this->assertFalse($result->allOk(), 'should be ok'); $this->assertEquals(1, $result->backupsFailedCount()); $this->assertEquals(1, $result->checksFailedCount()); $this->assertEquals(1, $result->errorCount()); $this->assertEquals(1, count($result->getErrors())); $this->assertEquals(1, count($result->getBackups())); }