1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Backup package, an RunOpenCode project. |
4
|
|
|
* |
5
|
|
|
* (c) 2015 RunOpenCode |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* This project is fork of "kbond/php-backup", for full credits info, please |
11
|
|
|
* view CREDITS file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
namespace RunOpenCode\Backup\Tests\Processor; |
14
|
|
|
|
15
|
|
|
use Psr\Log\NullLogger; |
16
|
|
|
use RunOpenCode\Backup\Contract\FileInterface; |
17
|
|
|
use RunOpenCode\Backup\Event\BackupEvent; |
18
|
|
|
use RunOpenCode\Backup\Processor\GzipArchiveProcessor; |
19
|
|
|
use RunOpenCode\Backup\Source\GlobSource; |
20
|
|
|
use RunOpenCode\Backup\Tests\Mockup\NullProfile; |
21
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
22
|
|
|
|
23
|
|
View Code Duplication |
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
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.