/** * Execute the cleanup. * * @param \phpbu\App\Configuration\Backup $backup * @param \phpbu\App\Backup\Target $target * @param \phpbu\App\Backup\Collector $collector * @throws \Exception */ protected function executeCleanup(Configuration\Backup $backup, Target $target, Collector $collector) { $cleanup = $backup->getCleanup(); if (!empty($cleanup)) { try { $this->result->cleanupStart($cleanup); if ($this->failure && $cleanup->skipOnFailure) { $this->result->cleanupSkipped($cleanup); } else { $cleaner = $this->factory->createCleaner($cleanup->type, $cleanup->options); $cleaner->cleanup($target, $collector, $this->result); $this->result->cleanupEnd($cleanup); } } catch (Backup\Cleaner\Exception $e) { $this->failure = true; $this->result->addError($e); $this->result->cleanupFailed($cleanup); } } }
/** * 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())); }