| @@ 23-68 (lines=46) @@ | ||
| 20 | use RunOpenCode\Backup\Tests\Mockup\NullProfile; |
|
| 21 | use Symfony\Component\EventDispatcher\EventDispatcher; |
|
| 22 | ||
| 23 | class GzipArchiveProcessorTest extends \PHPUnit_Framework_TestCase |
|
| 24 | { |
|
| 25 | /** |
|
| 26 | * @test |
|
| 27 | */ |
|
| 28 | public function gzipAndCleanUp() |
|
| 29 | { |
|
| 30 | $source = new GlobSource(realpath(__DIR__ . '/../Fixtures/glob/globSet1') . '/*'); |
|
| 31 | $files = $source->fetch(); |
|
| 32 | ||
| 33 | $this->assertSame(3, count($files), 'There are 3 files to archive.'); |
|
| 34 | ||
| 35 | $processor = new GzipArchiveProcessor('-czvf', 'archive.tar.gz'); |
|
| 36 | $processor->setLogger(new NullLogger()); |
|
| 37 | $processor->setEventDispatcher($eventDispatcher = new EventDispatcher()); |
|
| 38 | ||
| 39 | $processedFiles = $processor->process($files); |
|
| 40 | ||
| 41 | $this->assertSame(1, count($processedFiles), 'There is one compressed file'); |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @var FileInterface $processedFile |
|
| 45 | */ |
|
| 46 | $processedFile = $processedFiles[0]; |
|
| 47 | ||
| 48 | $this->assertTrue(file_exists($processedFile->getPath()), 'Gzip archive exists.'); |
|
| 49 | ||
| 50 | $eventDispatcher->dispatch(BackupEvent::TERMINATE, new BackupEvent(new NullProfile())); |
|
| 51 | ||
| 52 | $this->assertFalse(file_exists($processedFile->getPath()), 'Gzip archive is cleaned up.'); |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * @test |
|
| 57 | * |
|
| 58 | * @expectedException \RunOpenCode\Backup\Exception\ProcessorException |
|
| 59 | */ |
|
| 60 | public function couldNotProcessEmptyCollection() |
|
| 61 | { |
|
| 62 | $processor = new GzipArchiveProcessor('-czvf', 'archive.tar.gz'); |
|
| 63 | $processor->setLogger(new NullLogger()); |
|
| 64 | $processor->setEventDispatcher($eventDispatcher = new EventDispatcher()); |
|
| 65 | ||
| 66 | $processor->process(array()); |
|
| 67 | } |
|
| 68 | } |
|
| @@ 23-69 (lines=47) @@ | ||
| 20 | use RunOpenCode\Backup\Tests\Mockup\NullProfile; |
|
| 21 | use Symfony\Component\EventDispatcher\EventDispatcher; |
|
| 22 | ||
| 23 | class ZipArchiveProcessorTest extends \PHPUnit_Framework_TestCase |
|
| 24 | { |
|
| 25 | /** |
|
| 26 | * @test |
|
| 27 | */ |
|
| 28 | public function zipAndCleanUp() |
|
| 29 | { |
|
| 30 | $source = new GlobSource(realpath(__DIR__ . '/../Fixtures/glob/globSet1') . '/*'); |
|
| 31 | $files = $source->fetch(); |
|
| 32 | ||
| 33 | $this->assertSame(3, count($files), 'There are 3 files to archive.'); |
|
| 34 | ||
| 35 | $processor = new ZipArchiveProcessor('archive.zip'); |
|
| 36 | $processor->setLogger(new NullLogger()); |
|
| 37 | $processor->setEventDispatcher($eventDispatcher = new EventDispatcher()); |
|
| 38 | ||
| 39 | $processedFiles = $processor->process($files); |
|
| 40 | ||
| 41 | $this->assertSame(1, count($processedFiles), 'There is one compressed file'); |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @var FileInterface $processedFile |
|
| 45 | */ |
|
| 46 | $processedFile = $processedFiles[0]; |
|
| 47 | ||
| 48 | $this->assertTrue(file_exists($processedFile->getPath()), 'Zip archive exists.'); |
|
| 49 | ||
| 50 | $eventDispatcher->dispatch(BackupEvent::TERMINATE, new BackupEvent(new NullProfile())); |
|
| 51 | ||
| 52 | $this->assertFalse(file_exists($processedFile->getPath()), 'Zip archive is cleaned up.'); |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * @test |
|
| 57 | * |
|
| 58 | * @expectedException \RunOpenCode\Backup\Exception\ProcessorException |
|
| 59 | */ |
|
| 60 | public function couldNotProcessEmptyCollection() |
|
| 61 | { |
|
| 62 | $processor = new ZipArchiveProcessor('archive.zip'); |
|
| 63 | $processor->setLogger(new NullLogger()); |
|
| 64 | $processor->setEventDispatcher($eventDispatcher = new EventDispatcher()); |
|
| 65 | ||
| 66 | $processor->process(array()); |
|
| 67 | } |
|
| 68 | ||
| 69 | } |
|