/** * Compresses the target if the target is a directory. * * @param \phpbu\App\Backup\Target $target * @param \phpbu\App\Result $result * @param string $dataToCompress * @throws \phpbu\App\Exception */ protected function compressDirectory(Target $target, Result $result, $dataToCompress) { // archive data $dirCompressor = new Compressor\Directory($dataToCompress); $dirCompressor->compress($target, $result); // directory is archived but not compressed because tar couldn't handle the compression if (!file_exists($target->getPathname()) && file_exists($target->getPathnamePlain())) { // compress the tar with the configured compression $this->compressFile($target, $result, $target->getPathnamePlain()); } }
/** * Tests Directory::compress * * @expectedException \phpbu\App\Exception */ public function testCompressFail() { $dir = new Directory(__DIR__); $cliResult = $this->getCliResultMock(1, 'tar'); $target = $this->getTargetMock(__FILE__, __FILE__ . '.gz'); $target->method('getCompressor')->willReturn($this->getCompressorMock('gzip', 'gz')); $appResult = $this->getAppResultMock(); $tar = $this->getMockBuilder('\\phpbu\\App\\Cli\\Executable\\Tar')->disableOriginalConstructor()->getMock(); $tar->method('run')->willReturn($cliResult); $dir->setExecutable($tar); $dir->compress($target, $appResult); }