scratch – Blame information for rev 115

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 1 <?php
2  
3 namespace Neutron\TemporaryFilesystem\Tests;
4  
5 use Neutron\TemporaryFilesystem\Manager;
6  
7 class ManagerTest extends \PHPUnit_Framework_TestCase
8 {
9 public function testCreateEmptyFileAndCleanScope()
10 {
11 $basePath = 'basePath';
12 $prefix = 'prefix';
13 $suffix = 'suffix';
14 $extension = 'extension';
15 $maxTry = 'maxtry';
16  
17 $fs = $this->createFsMock();
18 $fs->expects($this->once())
19 ->method('remove')
20 ->with(array('/path/to/empty/file'));
21  
22 $tmpFs = $this->createTmpFsMock();
23 $tmpFs->expects($this->once())
24 ->method('createEmptyFile')
25 ->with($basePath, $prefix, $suffix, $extension, $maxTry)
26 ->will($this->returnValue('/path/to/empty/file'));
27  
28 $manager = new Manager($tmpFs, $fs);
29 $this->assertEquals('/path/to/empty/file', $manager->createEmptyFile($basePath, $prefix, $suffix, $extension, $maxTry));
30 $manager->clean($prefix);
31 }
32  
33 public function testCreateEmptyFileAndCleanOtherScope()
34 {
35 $basePath = 'basePath';
36 $prefix = 'prefix';
37 $suffix = 'suffix';
38 $extension = 'extension';
39 $maxTry = 'maxtry';
40  
41 $fs = $this->createFsMock();
42 $fs->expects($this->never())
43 ->method('remove');
44  
45 $tmpFs = $this->createTmpFsMock();
46 $tmpFs->expects($this->once())
47 ->method('createEmptyFile')
48 ->with($basePath, $prefix, $suffix, $extension, $maxTry)
49 ->will($this->returnValue('/path/to/empty/file'));
50  
51 $manager = new Manager($tmpFs, $fs);
52 $this->assertEquals('/path/to/empty/file', $manager->createEmptyFile($basePath, $prefix, $suffix, $extension, $maxTry));
53 $manager->clean('other prefix');
54 }
55  
56 public function testCreateEmptyFileAndCleanScopes()
57 {
58 $basePath = 'basePath';
59 $prefix = 'prefix';
60 $suffix = 'suffix';
61 $extension = 'extension';
62 $maxTry = 'maxtry';
63  
64 $fs = $this->createFsMock();
65 $fs->expects($this->once())
66 ->method('remove')
67 ->with(array('/path/to/empty/file'));
68  
69 $tmpFs = $this->createTmpFsMock();
70 $tmpFs->expects($this->once())
71 ->method('createEmptyFile')
72 ->with($basePath, $prefix, $suffix, $extension, $maxTry)
73 ->will($this->returnValue('/path/to/empty/file'));
74  
75 $manager = new Manager($tmpFs, $fs);
76 $this->assertEquals('/path/to/empty/file', $manager->createEmptyFile($basePath, $prefix, $suffix, $extension, $maxTry));
77 $manager->clean();
78 }
79  
80 public function testCreateTemporaryDirectoryAndCleanScope()
81 {
82 $mode = 'mode';
83 $prefix = 'prefix';
84 $maxTry = 'maxtry';
85  
86 $fs = $this->createFsMock();
87 $fs->expects($this->once())
88 ->method('remove')
89 ->with(array('/path/to/dir'));
90  
91 $tmpFs = $this->createTmpFsMock();
92 $tmpFs->expects($this->once())
93 ->method('createTemporaryDirectory')
94 ->with($mode, $maxTry, $prefix)
95 ->will($this->returnValue('/path/to/dir'));
96  
97 $manager = new Manager($tmpFs, $fs);
98 $this->assertEquals('/path/to/dir', $manager->createTemporaryDirectory($mode, $maxTry, $prefix));
99 $manager->clean($prefix);
100 }
101  
102 public function testCreateTemporaryDirectoryAndCleanOtherScope()
103 {
104 $mode = 'mode';
105 $prefix = 'prefix';
106 $maxTry = 'maxtry';
107  
108 $fs = $this->createFsMock();
109 $fs->expects($this->never())
110 ->method('remove');
111  
112 $tmpFs = $this->createTmpFsMock();
113 $tmpFs->expects($this->once())
114 ->method('createTemporaryDirectory')
115 ->with($mode, $maxTry, $prefix)
116 ->will($this->returnValue('/path/to/dir'));
117  
118 $manager = new Manager($tmpFs, $fs);
119 $this->assertEquals('/path/to/dir', $manager->createTemporaryDirectory($mode, $maxTry, $prefix));
120 $manager->clean('other prefix');
121 }
122  
123 public function testCreateTemporaryDirectoryAndCleanScopes()
124 {
125 $mode = 'mode';
126 $prefix = 'prefix';
127 $maxTry = 'maxtry';
128  
129 $fs = $this->createFsMock();
130 $fs->expects($this->once())
131 ->method('remove')
132 ->with(array('/path/to/dir'));
133  
134 $tmpFs = $this->createTmpFsMock();
135 $tmpFs->expects($this->once())
136 ->method('createTemporaryDirectory')
137 ->with($mode, $maxTry, $prefix)
138 ->will($this->returnValue('/path/to/dir'));
139  
140 $manager = new Manager($tmpFs, $fs);
141 $this->assertEquals('/path/to/dir', $manager->createTemporaryDirectory($mode, $maxTry, $prefix));
142 $manager->clean();
143 }
144  
145 public function testCreateTemporaryFileAndCleanScope()
146 {
147 $prefix = 'prefix';
148 $suffix = 'suffix';
149 $extension = 'extension';
150 $maxTry = 'maxtry';
151  
152 $fs = $this->createFsMock();
153 $fs->expects($this->once())
154 ->method('remove')
155 ->with(array('/path/to/file'));
156  
157 $tmpFs = $this->createTmpFsMock();
158 $tmpFs->expects($this->once())
159 ->method('createTemporaryFile')
160 ->with($prefix, $suffix, $extension, $maxTry)
161 ->will($this->returnValue('/path/to/file'));
162  
163 $manager = new Manager($tmpFs, $fs);
164 $this->assertEquals('/path/to/file', $manager->createTemporaryFile($prefix, $suffix, $extension, $maxTry));
165 $manager->clean($prefix);
166 }
167  
168 public function testCreateTemporaryFileAndCleanOtherScope()
169 {
170 $prefix = 'prefix';
171 $suffix = 'suffix';
172 $extension = 'extension';
173 $maxTry = 'maxtry';
174  
175 $fs = $this->createFsMock();
176 $fs->expects($this->never())
177 ->method('remove');
178  
179 $tmpFs = $this->createTmpFsMock();
180 $tmpFs->expects($this->once())
181 ->method('createTemporaryFile')
182 ->with($prefix, $suffix, $extension, $maxTry)
183 ->will($this->returnValue('/path/to/file'));
184  
185 $manager = new Manager($tmpFs, $fs);
186 $this->assertEquals('/path/to/file', $manager->createTemporaryFile($prefix, $suffix, $extension, $maxTry));
187 $manager->clean('other prefix');
188 }
189  
190 public function testCreateTemporaryFileAndCleanScopes()
191 {
192 $prefix = 'prefix';
193 $suffix = 'suffix';
194 $extension = 'extension';
195 $maxTry = 'maxtry';
196  
197 $fs = $this->createFsMock();
198 $fs->expects($this->once())
199 ->method('remove')
200 ->with(array('/path/to/file'));
201  
202 $tmpFs = $this->createTmpFsMock();
203 $tmpFs->expects($this->once())
204 ->method('createTemporaryFile')
205 ->with($prefix, $suffix, $extension, $maxTry)
206 ->will($this->returnValue('/path/to/file'));
207  
208 $manager = new Manager($tmpFs, $fs);
209 $this->assertEquals('/path/to/file', $manager->createTemporaryFile($prefix, $suffix, $extension, $maxTry));
210 $manager->clean();
211 }
212  
213 public function testCreateTemporaryFilesAndCleanScope()
214 {
215 $prefix = 'prefix';
216 $suffix = 'suffix';
217 $extension = 'extension';
218 $maxTry = 'maxtry';
219 $quantity = 123;
220  
221 $fs = $this->createFsMock();
222 $fs->expects($this->once())
223 ->method('remove')
224 ->with(array('/path/to/file'));
225  
226 $tmpFs = $this->createTmpFsMock();
227 $tmpFs->expects($this->once())
228 ->method('createTemporaryFiles')
229 ->with($quantity, $prefix, $suffix, $extension, $maxTry)
230 ->will($this->returnValue(array('/path/to/file')));
231  
232 $manager = new Manager($tmpFs, $fs);
233 $this->assertEquals(array('/path/to/file'), $manager->createTemporaryFiles($quantity, $prefix, $suffix, $extension, $maxTry));
234 $manager->clean($prefix);
235 }
236  
237 public function testCreateTemporaryFilesAndCleanOtherScope()
238 {
239 $prefix = 'prefix';
240 $suffix = 'suffix';
241 $extension = 'extension';
242 $maxTry = 'maxtry';
243 $quantity = 123;
244  
245 $fs = $this->createFsMock();
246 $fs->expects($this->never())
247 ->method('remove');
248  
249 $tmpFs = $this->createTmpFsMock();
250 $tmpFs->expects($this->once())
251 ->method('createTemporaryFiles')
252 ->with($quantity, $prefix, $suffix, $extension, $maxTry)
253 ->will($this->returnValue(array('/path/to/file')));
254  
255 $manager = new Manager($tmpFs, $fs);
256 $this->assertEquals(array('/path/to/file'), $manager->createTemporaryFiles($quantity, $prefix, $suffix, $extension, $maxTry));
257 $manager->clean('other prefix');
258 }
259  
260 public function testCreateTemporaryFilesAndCleanScopes()
261 {
262 $prefix = 'prefix';
263 $suffix = 'suffix';
264 $extension = 'extension';
265 $maxTry = 'maxtry';
266 $quantity = 123;
267  
268 $fs = $this->createFsMock();
269 $fs->expects($this->once())
270 ->method('remove')
271 ->with(array('/path/to/file'));
272  
273 $tmpFs = $this->createTmpFsMock();
274 $tmpFs->expects($this->once())
275 ->method('createTemporaryFiles')
276 ->with($quantity, $prefix, $suffix, $extension, $maxTry)
277 ->will($this->returnValue(array('/path/to/file')));
278  
279 $manager = new Manager($tmpFs, $fs);
280 $this->assertEquals(array('/path/to/file'), $manager->createTemporaryFiles($quantity, $prefix, $suffix, $extension, $maxTry));
281 $manager->clean();
282 }
283  
284 public function testCreate()
285 {
286 $this->assertInstanceOf('Neutron\TemporaryFilesystem\Manager', Manager::create());
287 }
288  
289 private function createTmpFsMock()
290 {
291 return $this->getMock('Neutron\TemporaryFilesystem\TemporaryFilesystemInterface');
292 }
293  
294 private function createFsMock()
295 {
296 return $this
297 ->getMockBuilder('Symfony\Component\Filesystem\Filesystem')
298 ->disableOriginalConstructor()
299 ->getMock();
300 }
301 }