|
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\Source; |
|
14
|
|
|
|
|
15
|
|
|
use RunOpenCode\Backup\Contract\FileInterface; |
|
16
|
|
|
use RunOpenCode\Backup\Source\GlobSource; |
|
17
|
|
|
use RunOpenCode\Backup\Source\SourceCollection; |
|
18
|
|
|
|
|
19
|
|
|
class SourceCollectionTest extends \PHPUnit_Framework_TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @test |
|
23
|
|
|
*/ |
|
24
|
|
|
public function sourceCollectionCombinesResultsFromSeveralSources() |
|
25
|
|
|
{ |
|
26
|
|
|
$source = new SourceCollection(); |
|
27
|
|
|
|
|
28
|
|
|
$source |
|
29
|
|
|
->add($src1 = new GlobSource(realpath(__DIR__ . '/../Fixtures/glob/globSet1') . '/*')) |
|
30
|
|
|
->add($src2 = new GlobSource(realpath(__DIR__ . '/../Fixtures/glob/globSet2') . '/*')); |
|
31
|
|
|
|
|
32
|
|
|
$files = $source->fetch(); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertSame(6, count($files), 'Collection returns all files from all sources.'); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertArraySubset( |
|
37
|
|
|
array('file1.txt', 'file2.txt', 'file3.txt', 'file4.txt', 'file5.txt', 'file6.txt'), |
|
38
|
|
|
array_map(function(FileInterface $file) { |
|
39
|
|
|
return $file->getName(); |
|
40
|
|
|
}, $files), |
|
41
|
|
|
false, |
|
42
|
|
|
'Has to have 6 specific files.' |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @test |
|
48
|
|
|
* |
|
49
|
|
|
* @expectedException \RunOpenCode\Backup\Exception\SourceException |
|
50
|
|
|
*/ |
|
51
|
|
|
public function ifOneSourceFailsWholeCollectionFails() |
|
52
|
|
|
{ |
|
53
|
|
|
$source = new SourceCollection(); |
|
54
|
|
|
|
|
55
|
|
|
$directory = realpath(__DIR__ . '/../Fixtures/glob/globCanNotReadThis'); |
|
56
|
|
|
|
|
57
|
|
|
chmod($directory, 0200); |
|
58
|
|
|
|
|
59
|
|
|
$source |
|
60
|
|
|
->add($src1 = new GlobSource(realpath(__DIR__ . '/../Fixtures/glob/globSet1') . '/*')) |
|
61
|
|
|
->add($src2 = new GlobSource($directory. '/*')); |
|
62
|
|
|
|
|
63
|
|
|
$source->fetch(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
} |