Completed
Push — master ( 0e2880...c1652d )
by Aimeos
05:28
created

lib/custom/tests/MW/Filesystem/FlyTest.php (6 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Aimeos\MW\Filesystem;
4
5
6
class FlyTest extends \PHPUnit\Framework\TestCase
7
{
8
	private $mock;
9
	private $object;
10
11
12
	protected function setUp()
13
	{
14
		if( !interface_exists( '\\League\\Flysystem\\FilesystemInterface' ) ) {
15
			$this->markTestSkipped( 'Install Flysystem first' );
16
		}
17
18
		$this->object = $this->getMockBuilder( '\\Aimeos\\MW\\Filesystem\\FlyNone' )
19
			->setConstructorArgs( array( array( 'adapter' => 'FlyNone' ) ) )
20
			->setMethods( array( 'getProvider' ) )
21
			->getMock();
22
23
		$this->mock = $this->getMockBuilder( '\\League\\Flysystem\\FilesystemInterface' )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object->expects( $this->once() )->method( 'getProvider' )
28
			->will( $this->returnValue( $this->mock ) );
29
	}
30
31
32
	protected function tearDown()
33
	{
34
		unset( $this->object, $this->mock );
35
	}
36
37
38 View Code Duplication
	public function testIsdir()
39
	{
40
		$this->mock->expects( $this->once() )->method( 'getMetadata' )
41
			->will( $this->returnValue( array( 'type' => 'dir' ) ) );
42
43
		$this->assertTrue( $this->object->isdir( 'test' ) );
44
	}
45
46
47 View Code Duplication
	public function testIsdirFalse()
48
	{
49
		$this->mock->expects( $this->once() )->method( 'getMetadata' )
50
			->will( $this->returnValue( array( 'type' => 'file' ) ) );
51
52
		$this->assertFalse( $this->object->isdir( 'test' ) );
53
	}
54
55
56 View Code Duplication
	public function testMkdir()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
	{
58
		$this->mock->expects( $this->once() )->method( 'createDir' )
59
			->will( $this->returnValue( true ) );
60
61
		$this->object->mkdir( 'test' );
62
	}
63
64
65 View Code Duplication
	public function testMkdirException()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
	{
67
		$this->mock->expects( $this->once() )->method( 'createDir' )
68
			->will( $this->returnValue( false ) );
69
70
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
71
		$this->object->mkdir( 'test' );
72
	}
73
74
75 View Code Duplication
	public function testRmdir()
76
	{
77
		$this->mock->expects( $this->once() )->method( 'deleteDir' )
78
			->will( $this->returnValue( true ) );
79
80
		$this->object->rmdir( 'test' );
81
	}
82
83
84 View Code Duplication
	public function testRmdirException()
85
	{
86
		$this->mock->expects( $this->once() )->method( 'deleteDir' )
87
			->will( $this->returnValue( false ) );
88
89
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
90
		$this->object->rmdir( 'test' );
91
	}
92
93
94
	public function testScan()
95
	{
96
		$this->mock->expects( $this->once() )->method( 'listContents' )
97
			->will( $this->returnValue( array( array( 'basename' => 'test' ) ) ) );
98
99
		$this->assertEquals( array( 'test' ), $this->object->scan() );
100
	}
101
102
103
	public function testSize()
104
	{
105
		$this->mock->expects( $this->once() )->method( 'getSize' )
106
			->will( $this->returnValue( 4 ) );
107
108
		$this->assertEquals( 4, $this->object->size( 'test' ) );
109
	}
110
111
112
	public function testSizeException()
113
	{
114
		$this->mock->expects( $this->once() )->method( 'getSize' )
115
			->will( $this->returnValue( false ) );
116
117
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
118
		$this->object->size( 'test' );
119
	}
120
121
122
	public function testSizeException2()
123
	{
124
		$this->mock->expects( $this->once() )->method( 'getSize' )
125
		->will( $this->throwException( new \RuntimeException() ) );
126
127
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
128
		$this->object->size( 'test' );
129
	}
130
131
132
	public function testTime()
133
	{
134
		$this->mock->expects( $this->once() )->method( 'getTimestamp' )
135
			->will( $this->returnValue( 4 ) );
136
137
		$this->assertEquals( 4, $this->object->time( 'test' ) );
138
	}
139
140
141 View Code Duplication
	public function testTimeException()
142
	{
143
		$this->mock->expects( $this->once() )->method( 'getTimestamp' )
144
			->will( $this->returnValue( false ) );
145
146
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
147
		$this->object->time( 'test' );
148
	}
149
150
151 View Code Duplication
	public function testTimeException2()
152
	{
153
		$this->mock->expects( $this->once() )->method( 'getTimestamp' )
154
			->will( $this->throwException( new \RuntimeException() ) );
155
156
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
157
		$this->object->time( 'test' );
158
	}
159
160
161
	public function testRm()
162
	{
163
		$this->mock->expects( $this->once() )->method( 'delete' )
164
		->will( $this->returnValue( 4 ) );
165
166
		$this->object->rm( 'test' );
167
	}
168
169
170
	public function testRmException()
171
	{
172
		$this->mock->expects( $this->once() )->method( 'delete' )
173
		->will( $this->throwException( new \RuntimeException() ) );
174
175
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
176
		$this->object->rm( 'test' );
177
	}
178
179
180 View Code Duplication
	public function testHas()
181
	{
182
		$this->mock->expects( $this->once() )->method( 'has' )
183
			->will( $this->returnValue( true ) );
184
185
		$result = $this->object->has( 'test' );
186
187
		$this->assertTrue( $result );
188
	}
189
190
191 View Code Duplication
	public function testHasFalse()
192
	{
193
		$this->mock->expects( $this->once() )->method( 'has' )
194
			->will( $this->returnValue( false ) );
195
196
		$result = $this->object->has( 'test' );
197
198
		$this->assertFalse( $result );
199
	}
200
201
202
	public function testRead()
203
	{
204
		$this->mock->expects( $this->once() )->method( 'read' )
205
			->will( $this->returnValue( 'value' ) );
206
207
		$this->assertEquals( 'value', $this->object->read( 'test' ) );
208
	}
209
210
211 View Code Duplication
	public function testReadException()
212
	{
213
		$this->mock->expects( $this->once() )->method( 'read' )
214
			->will( $this->returnValue( false ) );
215
216
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
217
		$this->object->read( 'test' );
218
	}
219
220
221 View Code Duplication
	public function testReadException2()
222
	{
223
		$this->mock->expects( $this->once() )->method( 'read' )
224
			->will( $this->throwException( new \RuntimeException() ) );
225
226
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
227
		$this->object->read( 'test' );
228
	}
229
230
231
	public function testReadf()
232
	{
233
		$file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'flytest';
234
		file_put_contents( $file, 'test' );
235
236
		$this->mock->expects( $this->once() )->method( 'readStream' )
237
			->will( $this->returnValue( fopen( $file, 'r' ) ) );
238
239
		$result = $this->object->readf( 'file' );
240
241
		$this->assertEquals( 'test', file_get_contents( $result ) );
242
243
		unlink( $result );
244
		unlink( $file );
245
	}
246
247
248 View Code Duplication
	public function testReads()
249
	{
250
		$this->mock->expects( $this->once() )->method( 'readStream' )
251
			->will( $this->returnValue( 1 ) );
252
253
		$this->assertEquals( 1, $this->object->reads( 'test' ) );
254
	}
255
256
257 View Code Duplication
	public function testReadsException()
258
	{
259
		$this->mock->expects( $this->once() )->method( 'readStream' )
260
			->will( $this->returnValue( false ) );
261
262
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
263
		$this->object->reads( 'test' );
264
	}
265
266
267 View Code Duplication
	public function testReadsException2()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
268
	{
269
		$this->mock->expects( $this->once() )->method( 'readStream' )
270
			->will( $this->throwException( new \RuntimeException() ) );
271
272
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
273
		$this->object->reads( 'test' );
274
	}
275
276
277 View Code Duplication
	public function testWrite()
278
	{
279
		$this->mock->expects( $this->once() )->method( 'put' )
280
			->will( $this->returnValue( true ) );
281
282
		$this->object->write( 'test', 'value' );
283
	}
284
285
286 View Code Duplication
	public function testWriteException()
287
	{
288
		$this->mock->expects( $this->once() )->method( 'put' )
289
			->will( $this->returnValue( false ) );
290
291
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
292
		$this->object->write( 'test', 'value' );
293
	}
294
295
296 View Code Duplication
	public function testWriteException2()
297
	{
298
		$this->mock->expects( $this->once() )->method( 'put' )
299
			->will( $this->throwException( new \RuntimeException() ) );
300
301
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
302
		$this->object->write( 'test', 'value' );
303
	}
304
305
306
	public function testWritef()
307
	{
308
		$file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'flytest';
309
		file_put_contents( $file, 'test' );
310
311
		$this->mock->expects( $this->once() )->method( 'putStream' );
312
313
		$this->object->writef( 'file', $file );
314
315
		unlink( $file );
316
	}
317
318
319 View Code Duplication
	public function testWrites()
320
	{
321
		$this->mock->expects( $this->once() )->method( 'putStream' )
322
			->will( $this->returnValue( true ) );
323
324
		$this->object->writes( 'test', 1 );
325
	}
326
327
328 View Code Duplication
	public function testWritesException()
329
	{
330
		$this->mock->expects( $this->once() )->method( 'putStream' )
331
			->will( $this->returnValue( false ) );
332
333
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
334
		$this->object->writes( 'test', 2 );
335
	}
336
337
338 View Code Duplication
	public function testWritesException2()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
339
	{
340
		$this->mock->expects( $this->once() )->method( 'putStream' )
341
			->will( $this->throwException( new \RuntimeException() ) );
342
343
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
344
		$this->object->writes( 'test', null );
345
	}
346
347
348 View Code Duplication
	public function testMove()
349
	{
350
		$this->mock->expects( $this->once() )->method( 'rename' )
351
			->will( $this->returnValue( true ) );
352
353
		$this->object->move( 'file1', 'file2' );
354
	}
355
356
357 View Code Duplication
	public function testMoveException()
358
	{
359
		$this->mock->expects( $this->once() )->method( 'rename' )
360
			->will( $this->returnValue( false ) );
361
362
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
363
		$this->object->move( 'file1', 'file2' );
364
	}
365
366
367 View Code Duplication
	public function testMoveException2()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
368
	{
369
		$this->mock->expects( $this->once() )->method( 'rename' )
370
			->will( $this->throwException( new \RuntimeException() ) );
371
372
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
373
		$this->object->move( 'file1', 'file2' );
374
	}
375
376
377 View Code Duplication
	public function testCopy()
378
	{
379
		$this->mock->expects( $this->once() )->method( 'copy' )
380
		->will( $this->returnValue( true ) );
381
382
		$this->object->copy( 'file1', 'file2' );
383
	}
384
385
386 View Code Duplication
	public function testCopyException()
387
	{
388
		$this->mock->expects( $this->once() )->method( 'copy' )
389
		->will( $this->returnValue( false ) );
390
391
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
392
		$this->object->copy( 'file1', 'file2' );
393
	}
394
395
396 View Code Duplication
	public function testCopyException2()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
397
	{
398
		$this->mock->expects( $this->once() )->method( 'copy' )
399
		->will( $this->throwException( new \RuntimeException() ) );
400
401
		$this->setExpectedException( '\Aimeos\MW\Filesystem\Exception' );
402
		$this->object->copy( 'file1', 'file2' );
403
	}
404
}
405