1 | <?php |
||
19 | class GlobSourceTest extends \PHPUnit_Framework_TestCase |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * @test |
||
24 | */ |
||
25 | public function singleGlob() |
||
26 | { |
||
27 | $source = new GlobSource(realpath(__DIR__ . '/../Fixtures/glob/globSet1') . '/*'); |
||
28 | $files = $source->fetch(); |
||
29 | |||
30 | $this->assertArraySubset( |
||
31 | array('file1.txt', 'file2.txt', 'file3.txt'), |
||
32 | array_map(function(FileInterface $file) { |
||
33 | return $file->getName(); |
||
34 | }, $files), |
||
35 | false, |
||
36 | 'Has to have 3 specific files.' |
||
37 | ); |
||
38 | |||
39 | $this->assertArraySubset( |
||
40 | array('file1.txt', 'file2.txt', 'file3.txt'), |
||
41 | array_map(function(FileInterface $file) { |
||
42 | return $file->getRelativePath(); |
||
43 | }, $files), |
||
44 | false, |
||
45 | 'Relative path must be filename since glob is root path.' |
||
46 | ); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @test |
||
51 | */ |
||
52 | public function multipleGlobs() |
||
53 | { |
||
54 | $source = new GlobSource(array( |
||
55 | realpath(__DIR__ . '/../Fixtures/glob/globSet1') . '/*' => realpath(__DIR__ . '/../Fixtures/glob'), |
||
56 | realpath(__DIR__ . '/../Fixtures/glob/globSet2') . '/*' => realpath(__DIR__ . '/../Fixtures/glob'), |
||
57 | )); |
||
58 | |||
59 | $files = $source->fetch(); |
||
60 | |||
61 | $this->assertArraySubset( |
||
62 | array('file1.txt', 'file2.txt', 'file3.txt', 'file4.txt', 'file5.txt', 'file6.txt'), |
||
63 | array_map(function(FileInterface $file) { |
||
64 | return $file->getName(); |
||
65 | }, $files), |
||
66 | false, |
||
67 | 'Has to have 6 specific files.' |
||
68 | ); |
||
69 | |||
70 | $this->assertArraySubset( |
||
71 | array('globSet1/file1.txt', 'globSet1/file2.txt', 'globSet1/file3.txt', 'globSet2/file4.txt', 'globSet2/file5.txt', 'globSet2/file6.txt'), |
||
72 | array_map(function(FileInterface $file) { |
||
73 | return $file->getRelativePath(); |
||
74 | }, $files), |
||
75 | false, |
||
76 | 'Relative path must be as defined since glob root path is given.' |
||
77 | ); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @test |
||
82 | * |
||
83 | * @expectedException \RunOpenCode\Backup\Exception\SourceException |
||
84 | */ |
||
85 | public function invalidGlob() |
||
86 | { |
||
87 | if(defined('HHVM_VERSION')) $this->markTestSkipped(); // non HHVM |
||
88 | |||
89 | $source = new GlobSource('/**/*.(txt)'); |
||
90 | $source->fetch(); |
||
91 | } |
||
92 | } |