5 require_once(
'./libs/composer/vendor/autoload.php');
6 \Hamcrest\Util::registerGlobalFunctions();
49 protected function setUp() : void
53 $this->filesystemMock = Mockery::mock(FilesystemInterface::class);
54 $this->fileAccessMock = Mockery::mock(FlySystemFileAccess::class);
65 $path =
'/path/to/dir';
69 'timestamp' => 10000000
73 ->shouldReceive(
'has')
77 ->shouldReceive(
'getMetadata')
79 ->andReturn($metadata);
81 $exists = $this->subject->hasDir($path);
82 $this->assertTrue($exists);
91 $path =
'/path/to/file';
95 'timestamp' => 10000000
99 ->shouldReceive(
'has')
103 ->shouldReceive(
'getMetadata')
105 ->andReturn($metadata);
107 $exists = $this->subject->hasDir($path);
108 $this->assertFalse($exists);
117 $path =
'/path/to/file';
120 'timestamp' => 10000000
123 $this->filesystemMock
124 ->shouldReceive(
'has')
128 ->shouldReceive(
'getMetadata')
130 ->andReturn($metadata);
132 $this->expectException(IOException::class);
133 $this->expectExceptionMessage(
"Could not evaluate path type: \"$path\"");
135 $exists = $this->subject->hasDir($path);
136 $this->assertFalse($exists);
145 $path =
'/path/to/dir';
147 $this->filesystemMock
148 ->shouldReceive(
'has')
152 $exists = $this->subject->hasDir($path);
153 $this->assertFalse($exists);
160 public function testListContentsWhichShouldSucceed()
162 $path =
'/path/to/dir';
163 $file = [
'type' =>
'file',
'path' => $path ];
164 $dir = [
'type' =>
'dir',
'path' => $path ];
171 $this->filesystemMock
172 ->shouldReceive(
'listContents')
174 ->withArgs([$path, \boolValue()])
175 ->andReturn($contentList)
177 ->shouldReceive(
'has')
182 ->shouldReceive(
'getMetadata')
190 $content = $this->subject->listContents($path);
192 $this->assertSame($contentList[0][
'type'], $content[0]->getType());
193 $this->assertSame($contentList[0][
'path'], $content[0]->getPath());
194 $this->assertTrue($content[0]->isFile());
195 $this->assertFalse($content[0]->isDir());
196 $this->assertSame($contentList[1][
'type'], $content[1]->getType());
197 $this->assertSame($contentList[1][
'path'], $content[1]->getPath());
198 $this->assertTrue($content[1]->isDir());
199 $this->assertFalse($content[1]->isFile());
208 $path =
'/path/to/dir';
210 $this->filesystemMock
211 ->shouldReceive(
'has')
215 $this->expectException(DirectoryNotFoundException::class);
216 $this->expectExceptionMessage(
"Directory \"$path\" not found.");
218 $this->subject->listContents($path);
227 $path =
'/path/to/dir';
228 $file = [
'type' =>
'file',
'path' => $path ];
229 $dir = [
'type' =>
'dir'];
237 $this->filesystemMock
238 ->shouldReceive(
'listContents')
240 ->andReturn($contentList)
242 ->shouldReceive(
'has')
246 ->shouldReceive(
'getMetadata')
250 $this->expectException(IOException::class);
251 $this->expectExceptionMessage(
"Invalid metadata received for path \"$path\"");
253 $this->subject->listContents($path);
262 $path =
'/path/to/dir';
265 $this->filesystemMock
266 ->shouldReceive(
'createDir')
268 ->withArgs([$path, [
'visibility' => $access]])
271 $this->subject->createDir($path, $access);
280 $path =
'/path/to/dir';
283 $this->filesystemMock
284 ->shouldReceive(
'createDir')
286 ->withArgs([$path, [
'visibility' => $access]])
289 $this->expectException(IOException::class);
290 $this->expectExceptionMessage(
"Could not create directory \"$path\"");
292 $this->subject->createDir($path, $access);
301 $path =
'/path/to/dir';
304 $this->expectException(\InvalidArgumentException::class);
305 $this->expectExceptionMessage(
"Invalid visibility expected public or private but got \"$access\".");
307 $this->subject->createDir($path, $access);
314 public function testCopyDirWhichShouldSucceed()
316 $srcPath =
'/source/path/to/dir';
317 $destPath =
'/dest/path/to/dir';
332 $fileDestinationList = [];
334 $subjectMock = Mockery::mock(FlySystemDirectoryAccess::class .
'[listContents, hasDir]', [$this->filesystemMock, $this->fileAccessMock]);
336 ->shouldReceive(
'listContents')
337 ->withArgs([$srcPath,
true])
339 ->andReturn($fileSourceList)
341 ->shouldReceive(
'listContents')
342 ->withArgs([$destPath,
true])
344 ->andReturn($fileDestinationList);
347 ->shouldReceive(
'hasDir')
352 $this->fileAccessMock
353 ->shouldReceive(
'copy')
354 ->withArgs([$fileSourceList[0]->getPath(),
"$destPath/hello1"])
357 ->shouldReceive(
'copy')
358 ->withArgs([$fileSourceList[2]->getPath(),
"$destPath/hello2"])
361 ->shouldReceive(
'copy')
362 ->withArgs([$fileSourceList[3]->getPath(),
"$destPath/hello/subhello1"])
365 ->shouldReceive(
'copy')
366 ->withArgs([$fileSourceList[5]->getPath(),
"$destPath/hello3"])
369 ->shouldReceive(
'copy')
370 ->withArgs([$fileSourceList[6]->getPath(),
"$destPath/hello/subhello2"])
375 $subjectMock->copyDir($srcPath, $destPath);
382 public function testCopyDirWithDestinationListContentErrorWhichShouldSucceed()
384 $srcPath =
'/source/path/to/dir';
385 $destPath =
'/dest/path/to/dir';
400 $subjectMock = Mockery::mock(FlySystemDirectoryAccess::class .
'[listContents, hasDir]', [$this->filesystemMock, $this->fileAccessMock]);
402 ->shouldReceive(
'listContents')
403 ->withArgs([$srcPath,
true])
405 ->andReturn($fileSourceList)
407 ->shouldReceive(
'listContents')
408 ->withArgs([$destPath,
true])
410 ->andThrow(DirectoryNotFoundException::class);
413 ->shouldReceive(
'hasDir')
418 $this->fileAccessMock
419 ->shouldReceive(
'copy')
420 ->withArgs([$fileSourceList[0]->getPath(),
"$destPath/hello1"])
423 ->shouldReceive(
'copy')
424 ->withArgs([$fileSourceList[2]->getPath(),
"$destPath/hello2"])
427 ->shouldReceive(
'copy')
428 ->withArgs([$fileSourceList[3]->getPath(),
"$destPath/hello/subhello1"])
431 ->shouldReceive(
'copy')
432 ->withArgs([$fileSourceList[5]->getPath(),
"$destPath/hello3"])
435 ->shouldReceive(
'copy')
436 ->withArgs([$fileSourceList[6]->getPath(),
"$destPath/hello/subhello2"])
441 $subjectMock->copyDir($srcPath, $destPath);
448 public function testCopyDirWithFullDestinationDirWhichShouldFail()
450 $srcPath =
'/source/path/to/dir';
451 $destPath =
'/dest/path/to/dir';
456 $fileDestinationList = [
466 $subjectMock = Mockery::mock(FlySystemDirectoryAccess::class .
'[listContents, hasDir]', [$this->filesystemMock, $this->fileAccessMock]);
468 ->shouldReceive(
'listContents')
469 ->withArgs([$destPath,
true])
471 ->andReturn($fileDestinationList);
474 ->shouldReceive(
'hasDir')
479 $this->expectException(IOException::class);
480 $this->expectExceptionMessage(
"Destination \"$destPath\" is not empty can not copy files.");
482 $subjectMock->copyDir($srcPath, $destPath);
491 $srcPath =
'/source/path/to/dir';
492 $destPath =
'/dest/path/to/dir';
494 $subjectMock = Mockery::mock(FlySystemDirectoryAccess::class .
'[hasDir]', [$this->filesystemMock, $this->fileAccessMock]);
496 ->shouldReceive(
'hasDir')
501 $this->expectException(DirectoryNotFoundException::class);
502 $this->expectExceptionMessage(
"Directory \"$srcPath\" not found");
504 $subjectMock->copyDir($srcPath, $destPath);
513 $path =
'/directory/which/should/be/removed';
515 $this->filesystemMock
516 ->shouldReceive(
'deleteDir')
521 $this->subject->deleteDir($path);
532 $this->filesystemMock
533 ->shouldReceive(
'deleteDir')
536 ->andThrow(RootViolationException::class);
538 $this->expectException(IOException::class);
539 $this->expectExceptionMessage(
'The filesystem root must not be deleted.');
541 $this->subject->deleteDir($path);
550 $path =
'/directory/which/should/be/removed';
552 $this->filesystemMock
553 ->shouldReceive(
'deleteDir')
558 $this->expectException(IOException::class);
559 $this->expectExceptionMessage(
"Could not delete directory \"$path\".");
561 $this->subject->deleteDir($path);
testListContentsWithInvalidMetadataWhichShouldFail()
testListContentsWithMissingRootDirectoryWhichShouldFail()
testHasDirWhichShouldSucceed()
testHasDirWithMissingDirWhichShouldSucceed()
const PRIVATE_ACCESS
Private file visibility.
testCreateDirWithGeneralErrorWhichShouldFail()
testCreateDirWithInvalidVisibilityWhichShouldFail()
testCreateDirWhichShouldSucceed()
testDeleteDirWithRootViolationWhichShouldFail()
testDeleteDirWithGeneralErrorWhichShouldFail()
testCopyDirWithMissingSourceDirWhichShouldFail()
Class FlySystemDirectoryAccessTest.
testHasDirWithFileTargetWhichShouldFail()
Class FlySystemDirectoryAccess.
testHasDirWithoutTypeInformationWhichShouldFail()
testDeleteDirWhichShouldSucceed()