1 | <?php |
||
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 | if(defined('HHVM_VERSION')) $this->markTestSkipped(); // non HHVM |
||
54 | |||
55 | $source = new SourceCollection(); |
||
56 | |||
57 | $source |
||
58 | ->add(new GlobSource(realpath(__DIR__ . '/../Fixtures/glob/globSet1') . '/*')) |
||
59 | ->add(new GlobSource('/**/*.(txt)')); |
||
60 | |||
61 | $source->fetch(); |
||
62 | } |
||
63 | |||
64 | } |