/** * Executes a backup check. * * @param \phpbu\App\Backup\Check $check * @param \phpbu\App\Configuration\Backup\Check $config * @param \phpbu\App\Backup\Target $target * @param \phpbu\App\Backup\Collector $collector * @param \phpbu\App\Result $result */ public function run(CheckExe $check, CheckConfig $config, Target $target, Collector $collector, Result $result) { try { $result->checkStart($config); if ($check->pass($target, $config->value, $collector, $result)) { $result->checkEnd($config); } else { $this->failure = true; $result->checkFailed($config); } } catch (Exception $e) { $this->failure = true; $result->addError($e); $result->checkFailed($config); } }
/** * 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())); }