5 require_once(
'./libs/composer/vendor/autoload.php');
52 $this->filesystemMock = Mockery::mock(FilesystemInterface::class);
53 $this->fileAccessMock = Mockery::mock(FlySystemFileAccess::class);
64 $path =
'/path/to/dir';
68 'timestamp' => 10000000
72 ->shouldReceive(
'has')
76 ->shouldReceive(
'getMetadata')
80 $exists = $this->subject->hasDir(
$path);
81 $this->assertTrue($exists);
90 $path =
'/path/to/file';
94 'timestamp' => 10000000
98 ->shouldReceive(
'has')
102 ->shouldReceive(
'getMetadata')
106 $exists = $this->subject->hasDir(
$path);
107 $this->assertFalse($exists);
116 $path =
'/path/to/file';
119 'timestamp' => 10000000
122 $this->filesystemMock
123 ->shouldReceive(
'has')
127 ->shouldReceive(
'getMetadata')
131 $this->expectException(IOException::class);
132 $this->expectExceptionMessage(
"Could not evaluate path type: \"$path\"");
134 $exists = $this->subject->hasDir(
$path);
135 $this->assertFalse($exists);
144 $path =
'/path/to/dir';
146 $this->filesystemMock
147 ->shouldReceive(
'has')
151 $exists = $this->subject->hasDir(
$path);
152 $this->assertFalse($exists);
159 public function testListContentsWhichShouldSucceed()
161 $path =
'/path/to/dir';
162 $file = [
'type' =>
'file',
'path' =>
$path ];
163 $dir = [
'type' =>
'dir',
'path' =>
$path ];
170 $this->filesystemMock
171 ->shouldReceive(
'listContents')
173 ->withArgs([
$path, boolValue()])
174 ->andReturn($contentList)
176 ->shouldReceive(
'has')
181 ->shouldReceive(
'getMetadata')
189 $content = $this->subject->listContents(
$path);
191 $this->assertSame($contentList[0][
'type'], $content[0]->getType());
192 $this->assertSame($contentList[0][
'path'], $content[0]->getPath());
193 $this->assertTrue($content[0]->isFile());
194 $this->assertFalse($content[0]->isDir());
195 $this->assertSame($contentList[1][
'type'], $content[1]->getType());
196 $this->assertSame($contentList[1][
'path'], $content[1]->getPath());
197 $this->assertTrue($content[1]->isDir());
198 $this->assertFalse($content[1]->isFile());
207 $path =
'/path/to/dir';
209 $this->filesystemMock
210 ->shouldReceive(
'has')
214 $this->expectException(DirectoryNotFoundException::class);
215 $this->expectExceptionMessage(
"Directory \"$path\" not found.");
217 $this->subject->listContents(
$path);
226 $path =
'/path/to/dir';
227 $file = [
'type' =>
'file',
'path' =>
$path ];
228 $dir = [
'type' =>
'dir'];
236 $this->filesystemMock
237 ->shouldReceive(
'listContents')
239 ->andReturn($contentList)
241 ->shouldReceive(
'has')
245 ->shouldReceive(
'getMetadata')
249 $this->expectException(IOException::class);
250 $this->expectExceptionMessage(
"Invalid metadata received for path \"$path\"");
252 $this->subject->listContents(
$path);
261 $path =
'/path/to/dir';
264 $this->filesystemMock
265 ->shouldReceive(
'createDir')
267 ->withArgs([
$path, [
'visibility' => $access]])
270 $this->subject->createDir(
$path, $access);
279 $path =
'/path/to/dir';
282 $this->filesystemMock
283 ->shouldReceive(
'createDir')
285 ->withArgs([
$path, [
'visibility' => $access]])
288 $this->expectException(IOException::class);
289 $this->expectExceptionMessage(
"Could not create directory \"$path\"");
291 $this->subject->createDir(
$path, $access);
300 $path =
'/path/to/dir';
303 $this->expectException(\InvalidArgumentException::class);
304 $this->expectExceptionMessage(
"Invalid visibility expected public or private but got \"$access\".");
306 $this->subject->createDir(
$path, $access);
313 public function testCopyDirWhichShouldSucceed()
315 $srcPath =
'/source/path/to/dir';
316 $destPath =
'/dest/path/to/dir';
331 $fileDestinationList = [];
333 $subjectMock = Mockery::mock(FlySystemDirectoryAccess::class .
'[listContents, hasDir]', [$this->filesystemMock, $this->fileAccessMock]);
335 ->shouldReceive(
'listContents')
336 ->withArgs([$srcPath,
true])
338 ->andReturn($fileSourceList)
340 ->shouldReceive(
'listContents')
341 ->withArgs([$destPath,
true])
343 ->andReturn($fileDestinationList);
346 ->shouldReceive(
'hasDir')
351 $this->fileAccessMock
352 ->shouldReceive(
'copy')
353 ->withArgs([$fileSourceList[0]->getPath(),
"$destPath/hello1"])
356 ->shouldReceive(
'copy')
357 ->withArgs([$fileSourceList[2]->getPath(),
"$destPath/hello2"])
360 ->shouldReceive(
'copy')
361 ->withArgs([$fileSourceList[3]->getPath(),
"$destPath/hello/subhello1"])
364 ->shouldReceive(
'copy')
365 ->withArgs([$fileSourceList[5]->getPath(),
"$destPath/hello3"])
368 ->shouldReceive(
'copy')
369 ->withArgs([$fileSourceList[6]->getPath(),
"$destPath/hello/subhello2"])
374 $subjectMock->copyDir($srcPath, $destPath);
381 public function testCopyDirWithDestinationListContentErrorWhichShouldSucceed()
383 $srcPath =
'/source/path/to/dir';
384 $destPath =
'/dest/path/to/dir';
399 $subjectMock = Mockery::mock(FlySystemDirectoryAccess::class .
'[listContents, hasDir]', [$this->filesystemMock, $this->fileAccessMock]);
401 ->shouldReceive(
'listContents')
402 ->withArgs([$srcPath,
true])
404 ->andReturn($fileSourceList)
406 ->shouldReceive(
'listContents')
407 ->withArgs([$destPath,
true])
409 ->andThrow(DirectoryNotFoundException::class);
412 ->shouldReceive(
'hasDir')
417 $this->fileAccessMock
418 ->shouldReceive(
'copy')
419 ->withArgs([$fileSourceList[0]->getPath(),
"$destPath/hello1"])
422 ->shouldReceive(
'copy')
423 ->withArgs([$fileSourceList[2]->getPath(),
"$destPath/hello2"])
426 ->shouldReceive(
'copy')
427 ->withArgs([$fileSourceList[3]->getPath(),
"$destPath/hello/subhello1"])
430 ->shouldReceive(
'copy')
431 ->withArgs([$fileSourceList[5]->getPath(),
"$destPath/hello3"])
434 ->shouldReceive(
'copy')
435 ->withArgs([$fileSourceList[6]->getPath(),
"$destPath/hello/subhello2"])
440 $subjectMock->copyDir($srcPath, $destPath);
447 public function testCopyDirWithFullDestinationDirWhichShouldFail()
449 $srcPath =
'/source/path/to/dir';
450 $destPath =
'/dest/path/to/dir';
455 $fileDestinationList = [
465 $subjectMock = Mockery::mock(FlySystemDirectoryAccess::class .
'[listContents, hasDir]', [$this->filesystemMock, $this->fileAccessMock]);
467 ->shouldReceive(
'listContents')
468 ->withArgs([$destPath,
true])
470 ->andReturn($fileDestinationList);
473 ->shouldReceive(
'hasDir')
478 $this->expectException(IOException::class);
479 $this->expectExceptionMessage(
"Destination \"$destPath\" is not empty can not copy files.");
481 $subjectMock->copyDir($srcPath, $destPath);
490 $srcPath =
'/source/path/to/dir';
491 $destPath =
'/dest/path/to/dir';
493 $subjectMock = Mockery::mock(FlySystemDirectoryAccess::class .
'[hasDir]', [$this->filesystemMock, $this->fileAccessMock]);
495 ->shouldReceive(
'hasDir')
500 $this->expectException(DirectoryNotFoundException::class);
501 $this->expectExceptionMessage(
"Directory \"$srcPath\" not found");
503 $subjectMock->copyDir($srcPath, $destPath);
512 $path =
'/directory/which/should/be/removed';
514 $this->filesystemMock
515 ->shouldReceive(
'deleteDir')
520 $this->subject->deleteDir(
$path);
531 $this->filesystemMock
532 ->shouldReceive(
'deleteDir')
535 ->andThrow(RootViolationException::class);
537 $this->expectException(IOException::class);
538 $this->expectExceptionMessage(
'The filesystem root must not be deleted.');
540 $this->subject->deleteDir(
$path);
549 $path =
'/directory/which/should/be/removed';
551 $this->filesystemMock
552 ->shouldReceive(
'deleteDir')
557 $this->expectException(IOException::class);
558 $this->expectExceptionMessage(
"Could not delete directory \"$path\".");
560 $this->subject->deleteDir(
$path);
testListContentsWithInvalidMetadataWhichShouldFail()
testListContentsWithMissingRootDirectoryWhichShouldFail()
testHasDirWhichShouldSucceed()
testHasDirWithMissingDirWhichShouldSucceed()
$metadata['__DYNAMIC:1__']
const PRIVATE_ACCESS
Private file visibility.
testCreateDirWithGeneralErrorWhichShouldFail()
testCreateDirWithInvalidVisibilityWhichShouldFail()
testCreateDirWhichShouldSucceed()
testDeleteDirWithRootViolationWhichShouldFail()
testDeleteDirWithGeneralErrorWhichShouldFail()
testCopyDirWithMissingSourceDirWhichShouldFail()
Class FlySystemDirectoryAccessTest.
testHasDirWithFileTargetWhichShouldFail()
Class FlySystemDirectoryAccess.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
testHasDirWithoutTypeInformationWhichShouldFail()
testDeleteDirWhichShouldSucceed()