/** * Execute encryption. * * @param \phpbu\App\Configuration\Backup $backup * @param \phpbu\App\Backup\Target $target */ protected function executeCrypt(Configuration\Backup $backup, Target $target) { $crypt = $backup->getCrypt(); if (!empty($crypt)) { try { $this->result->cryptStart($crypt); if ($this->failure && $crypt->skipOnFailure) { $this->result->cryptSkipped($crypt); } else { $c = $this->factory->createCrypter($crypt->type, $crypt->options); $c->crypt($target, $this->result); $target->setCrypter($c); } } catch (Backup\Crypter\Exception $e) { $this->failure = true; $this->result->addError($e); $this->result->cryptFailed($crypt); } } }
/** * Tests max Result life cycle with errors. */ public function testBackupMaximalWithErrors() { $conf = new Configuration('/tmp/foo.xml'); $backup = new Configuration\Backup('test-backup', false); $check = new Configuration\Backup\Check('sizemin', '10M'); $crypt = new Configuration\Backup\Crypt('mcrypt', false); $sync = new Configuration\Backup\Sync('rsync', false); $cleanup = new Configuration\Backup\Cleanup('capacity', false); $result = new Result(); $result->phpbuStart($conf); $result->backupStart($backup); $result->checkStart($check); $result->checkEnd($check); $result->cryptStart($crypt); $result->addError(new Exception('failed')); $result->cryptFailed($crypt); $result->syncStart($sync); $result->addError(new Exception('failed')); $result->syncFailed($sync); $result->cleanupStart($cleanup); $result->addError(new Exception('failed')); $result->cleanupFailed($cleanup); $result->backupEnd($backup); $result->phpbuEnd(); $this->assertTrue($result->wasSuccessful(), 'should be successful'); $this->assertFalse($result->allOk(), 'should be ok'); $this->assertTrue($result->backupOkButSkipsOrFails(), 'crypt, sync and cleanup should be failed'); $this->assertEquals(1, $result->syncsFailedCount()); $this->assertEquals(0, $result->syncsSkippedCount()); $this->assertEquals(1, $result->cryptsFailedCount()); $this->assertEquals(0, $result->cryptsSkippedCount()); $this->assertEquals(1, $result->cleanupsFailedCount()); $this->assertEquals(0, $result->cleanupsSkippedCount()); $this->assertEquals(3, $result->errorCount()); $this->assertEquals(3, count($result->getErrors())); $this->assertEquals(1, count($result->getBackups())); }