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