1 | <?php |
||
14 | class FileCollectionTest extends \PHPUnit_Framework_TestCase |
||
15 | { |
||
16 | /** |
||
17 | * @dataProvider fileProvider |
||
18 | */ |
||
19 | public function testAdd($files) |
||
20 | { |
||
21 | // Create collection |
||
22 | $fc = new FileCollection(); |
||
23 | $this->assertCount(0, $fc); |
||
24 | |||
25 | // Add some files |
||
26 | $fc->addFile($files[0]); |
||
27 | $this->assertCount(1, $fc); |
||
28 | |||
29 | $fc->addFile($files[1]); |
||
30 | $this->assertCount(2, $fc); |
||
31 | |||
32 | // Igrore adding the same file |
||
33 | $fc->addFile($files[0]); |
||
34 | $this->assertCount(2, $fc); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @dataProvider fileProvider |
||
39 | */ |
||
40 | public function testFilter($files) |
||
41 | { |
||
42 | $filter1 = $this->getMockBuilder(FilterInterface::class) |
||
43 | ->setMethods(['valid']) |
||
44 | ->getMock(); |
||
45 | $filter1 |
||
46 | ->expects($this->exactly(count($files))) |
||
47 | ->method('valid') |
||
48 | ->willReturn(true); |
||
49 | $filter2 = $this->getMockBuilder(FilterInterface::class) |
||
50 | ->setMethods(['valid']) |
||
51 | ->getMock(); |
||
52 | $filter2 |
||
53 | ->expects($this->exactly(count($files))) |
||
54 | ->method('valid') |
||
55 | ->willReturn(true); |
||
56 | |||
57 | $fc = new FileCollection(); |
||
58 | foreach ($files as $file) { |
||
59 | $fc->addFile($file); |
||
60 | } |
||
61 | |||
62 | $fc->filter([$filter1, $filter2]); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @dataProvider fileProvider |
||
67 | */ |
||
68 | public function testIndex($files) |
||
69 | { |
||
70 | // Create collection |
||
71 | $fc = new FileCollection(); |
||
72 | |||
73 | // Add some files |
||
74 | $fc->addFile($files[0]); |
||
75 | $fc->addFile($files[1]); |
||
76 | $fc->addFile($files[0]); |
||
77 | $fc->addFile($files[2]); |
||
78 | $fc->del($files[0]->getPath()); |
||
79 | |||
80 | /** |
||
81 | * Get from index |
||
82 | * |
||
83 | * @var File $file |
||
84 | */ |
||
85 | $file = $files[2]; |
||
86 | $this->assertEquals($file, $fc->getByUid($file->getUid())); |
||
87 | |||
88 | $fc->del($file->getPath()); |
||
89 | $this->assertNull($fc->getByUid($file->getUid())); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @dataProvider fileProvider |
||
94 | * @expectedException \AppBundle\Exception\FilterException |
||
95 | */ |
||
96 | public function testBadFilter($files) |
||
97 | { |
||
98 | $fc = new FileCollection(); |
||
99 | foreach ($files as $file) { |
||
100 | $fc->addFile($file); |
||
101 | } |
||
102 | |||
103 | $fc->filter(['bad filter']); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @dataProvider fileProvider |
||
108 | * @expectedException \AppBundle\Exception\FilterException |
||
109 | */ |
||
110 | public function testBadFilterWithObject($files) |
||
111 | { |
||
112 | $fc = new FileCollection(); |
||
113 | foreach ($files as $file) { |
||
114 | $fc->addFile($file); |
||
115 | } |
||
116 | |||
117 | $fc->filter([new \stdClass()]); |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * @dataProvider fileProvider |
||
122 | */ |
||
123 | public function testGetByUid($files) |
||
124 | { |
||
125 | /** |
||
126 | * @var File $file |
||
127 | */ |
||
128 | $file = $files[0]; |
||
129 | $fc = new FileCollection(); |
||
130 | $fc->addFile($file); |
||
131 | |||
132 | $this->assertEquals($file, $fc->getByUid($file->getUid())); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * @dataProvider fileProvider |
||
137 | */ |
||
138 | public function testCorruptedIndex($files) |
||
157 | |||
158 | public function fileProvider() |
||
159 | { |
||
160 | $files = []; |
||
161 | |||
162 | $file = new File(); |
||
163 | $file->setUid('TEST00113.mov'); |
||
185 | } |
||
186 |