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