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
|
|
|
|
16
|
|
|
use Psr\Log\NullLogger; |
17
|
|
|
use RunOpenCode\Backup\Contract\FileInterface; |
18
|
|
|
use RunOpenCode\Backup\Source\Glob; |
19
|
|
|
|
20
|
|
|
class GlobSourceTest extends \PHPUnit_Framework_TestCase |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @test |
25
|
|
|
*/ |
26
|
|
|
public function singleGlob() |
27
|
|
|
{ |
28
|
|
|
$source = new Glob(realpath(__DIR__ . '/../Fixtures/glob/globSet1') . '/*'); |
29
|
|
|
$files = $source->fetch(); |
30
|
|
|
|
31
|
|
|
$this->assertArraySubset( |
32
|
|
|
array('file1.txt', 'file2.txt', 'file3.txt'), |
33
|
|
|
array_map(function(FileInterface $file) { |
34
|
|
|
return $file->getName(); |
35
|
|
|
}, $files), |
36
|
|
|
false, |
37
|
|
|
'Has to have 3 specific files.' |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
$this->assertArraySubset( |
41
|
|
|
array('file1.txt', 'file2.txt', 'file3.txt'), |
42
|
|
|
array_map(function(FileInterface $file) { |
43
|
|
|
return $file->getRelativePath(); |
44
|
|
|
}, $files), |
45
|
|
|
false, |
46
|
|
|
'Relative path must be filename since glob is root path.' |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @test |
52
|
|
|
*/ |
53
|
|
|
public function multipleGlobs() |
54
|
|
|
{ |
55
|
|
|
$source = new Glob(array( |
56
|
|
|
realpath(__DIR__ . '/../Fixtures/glob/globSet1') . '/*' => realpath(__DIR__ . '/../Fixtures/glob'), |
57
|
|
|
realpath(__DIR__ . '/../Fixtures/glob/globSet2') . '/*' => realpath(__DIR__ . '/../Fixtures/glob'), |
58
|
|
|
)); |
59
|
|
|
|
60
|
|
|
$files = $source->fetch(); |
61
|
|
|
|
62
|
|
|
$this->assertArraySubset( |
63
|
|
|
array('file1.txt', 'file2.txt', 'file3.txt', 'file4.txt', 'file5.txt', 'file6.txt'), |
64
|
|
|
array_map(function(FileInterface $file) { |
65
|
|
|
return $file->getName(); |
66
|
|
|
}, $files), |
67
|
|
|
false, |
68
|
|
|
'Has to have 6 specific files.' |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
$this->assertArraySubset( |
72
|
|
|
array('globSet1/file1.txt', 'globSet1/file2.txt', 'globSet1/file3.txt', 'globSet2/file4.txt', 'globSet2/file5.txt', 'globSet2/file6.txt'), |
73
|
|
|
array_map(function(FileInterface $file) { |
74
|
|
|
return $file->getRelativePath(); |
75
|
|
|
}, $files), |
76
|
|
|
false, |
77
|
|
|
'Relative path must be as define since glob root path is given.' |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @test |
83
|
|
|
* |
84
|
|
|
* @expectedException \RunOpenCode\Backup\Exception\SourceException |
85
|
|
|
*/ |
86
|
|
|
public function invalidGlob() |
87
|
|
|
{ |
88
|
|
|
$directory = realpath(__DIR__ . '/../Fixtures/glob/globCanNotReadThis'); |
89
|
|
|
|
90
|
|
|
@chmod($directory, 0200); |
|
|
|
|
91
|
|
|
|
92
|
|
|
$source = new Glob($directory . '/*'); |
93
|
|
|
$source->setLogger(new NullLogger()); |
94
|
|
|
$files = $source->fetch(); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
} |
If you suppress an error, we recommend checking for the error condition explicitly: