1 | <?php |
||
25 | class MetadataFinderTest extends TestCase |
||
26 | { |
||
27 | public function testInstanceOf() |
||
28 | { |
||
29 | $finder = new MetadataFinder(new AllOfFilter()); |
||
30 | static::assertInstanceOf(FileFinderInterface::class, $finder); |
||
31 | } |
||
32 | |||
33 | public function testFindFilesWithNoFiltersWillReturnAllFiles() |
||
34 | { |
||
35 | $file = m::mock(FileNode::class); |
||
36 | $file->shouldReceive('getMetadata') |
||
37 | ->andReturn([ |
||
38 | 'name' => 'test', |
||
39 | ]); |
||
40 | $collection = new FileNodeCollection(); |
||
41 | $collection->add($file); |
||
42 | |||
43 | $filter = m::mock(ArrayFilterInterface::class); |
||
44 | $filter->shouldReceive('matches')->andReturn(true); |
||
45 | $finder = new MetadataFinder($filter); |
||
46 | |||
47 | static::assertEquals($collection->getAll(), $finder->findFiles($collection)->getAll()); |
||
48 | } |
||
49 | |||
50 | public function testFindFilesWithWithBasicFiltersWillReturnMatchingFilesOnly() |
||
51 | { |
||
52 | $file = m::mock(FileNode::class); |
||
53 | $file->shouldReceive('getMetadata') |
||
54 | ->andReturn([ |
||
55 | 'name' => 'test', |
||
56 | ]); |
||
57 | $file2 = m::mock(FileNode::class); |
||
58 | $file2->shouldReceive('getMetadata') |
||
59 | ->andReturn([ |
||
60 | 'name' => 'test2', |
||
61 | ]); |
||
62 | $collection = new FileNodeCollection(); |
||
63 | $collection->add($file); |
||
64 | $collection->add($file2); |
||
65 | |||
66 | $filter = m::mock(ArrayFilterInterface::class); |
||
67 | $filter->shouldReceive('matches')->with(['name' => 'test'])->andReturn(true); |
||
68 | $filter->shouldReceive('matches')->with(['name' => 'test2'])->andReturn(false); |
||
69 | $finder = new MetadataFinder($filter); |
||
70 | |||
71 | $found = $finder->findFiles($collection); |
||
72 | static::assertCount(1, $found->getAll()); |
||
73 | static::assertEquals([$file], $found->getAll()); |
||
74 | } |
||
75 | |||
76 | public function testFindFilesReturningFalseWillNotIncludeTheFileInTheResults() |
||
88 | } |
||
89 |