5 require_once(
'./libs/composer/vendor/autoload.php');
49 protected function setUp() : void
53 $this->filesystemMock = Mockery::mock(FilesystemInterface::class);
54 $this->adapterMock = Mockery::mock(AdapterInterface::class);
64 $fileContent =
'Test file content.';
66 $this->adapterMock->shouldReceive(
'read')
68 ->andReturn([
'contents' => $fileContent]);
70 $this->adapterMock->shouldReceive(
'has')
74 $this->filesystemMock->shouldReceive(
'getAdapter')
76 ->andReturn($this->adapterMock);
78 $actualContent = $this->subject->read(
'/path/to/your/file');
79 $this->assertSame($fileContent, $actualContent);
88 $path =
'path/to/your/file';
90 $this->adapterMock->shouldReceive(
'has')
94 $this->adapterMock->shouldReceive(
'read')
96 ->andReturn([
'contents' =>
false]);
98 $this->filesystemMock->shouldReceive(
'getAdapter')
100 ->andReturn($this->adapterMock);
102 $this->expectException(IOException::class);
103 $this->expectExceptionMessage(
"Could not access the file \"$path\".");
105 $this->subject->read($path);
114 $path =
'path/to/your/file';
116 $this->adapterMock->shouldReceive(
'has')
120 $this->filesystemMock->shouldReceive(
'getAdapter')
122 ->andReturn($this->adapterMock);
125 $this->expectExceptionMessage(
"File \"$path\" not found.");
127 $this->subject->read(
'/' . $path);
136 $mimeType =
'image/jpeg';
137 $this->filesystemMock->shouldReceive(
'getMimetype')
139 ->andReturn($mimeType);
141 $actualMimeType = $this->subject->getMimeType(
'/path/to/your/file');
142 $this->assertSame($mimeType, $actualMimeType);
151 $path =
'/path/to/your/file';
152 $this->filesystemMock->shouldReceive(
'getMimetype')
157 $this->expectException(IOException::class);
158 $this->expectExceptionMessage(
"Could not determine the MIME type of the file \"$path\".");
160 $this->subject->getMimeType($path);
169 $path =
'/path/to/your/file';
170 $this->filesystemMock->shouldReceive(
'getMimetype')
173 ->andThrow(FileNotFoundException::class);
176 $this->expectExceptionMessage(
"File \"$path\" not found.");
178 $this->subject->getMimeType($path);
188 $this->filesystemMock->shouldReceive(
'getTimestamp')
192 $actualTimestamp = $this->subject->getTimestamp(
'/path/to/your/file');
205 $this->assertEquals(
new \DateTime(
$timestamp), $actualTimestamp);
214 $path =
'/path/to/your/file';
215 $this->filesystemMock->shouldReceive(
'getTimestamp')
220 $this->expectException(IOException::class);
221 $this->expectExceptionMessage(
"Could not lookup timestamp of the file \"$path\".");
223 $this->subject->getTimestamp($path);
232 $path =
'/path/to/your/file';
233 $this->filesystemMock->shouldReceive(
'getTimestamp')
236 ->andThrow(FileNotFoundException::class);
239 $this->expectExceptionMessage(
"File \"$path\" not found.");
241 $this->subject->getTimestamp($path);
254 $this->filesystemMock->shouldReceive(
'getSize')
256 ->andReturn($rawSize);
258 $actualSize = $this->subject->getSize(
'/path/to/your/file',
DataSize::KiB);
259 $this->assertSame(
$size->getSize(), $actualSize->getSize(),
'', $delta);
268 $path =
'/path/to/your/file';
269 $this->filesystemMock->shouldReceive(
'getSize')
274 $this->expectException(IOException::class);
275 $this->expectExceptionMessage(
"Could not calculate the file size of the file \"$path\".");
286 $path =
'/path/to/your/file';
287 $this->filesystemMock->shouldReceive(
'getSize')
290 ->andThrow(FileNotFoundException::class);
293 $this->expectExceptionMessage(
"File \"$path\" not found.");
304 $path =
'/path/to/your/file';
305 $visibility =
"private";
307 $this->filesystemMock->shouldReceive(
'has')
312 $this->filesystemMock->shouldReceive(
'setVisibility')
314 ->withArgs([$path, $visibility])
317 $operationSuccessful = $this->subject->setVisibility($path, $visibility);
318 $this->assertTrue($operationSuccessful);
327 $path =
'/path/to/your/file';
328 $visibility =
"private";
330 $this->filesystemMock->shouldReceive(
'has')
335 $this->filesystemMock->shouldReceive(
'setVisibility')
337 ->withArgs([$path, $visibility])
340 $operationSuccessful = $this->subject->setVisibility($path, $visibility);
341 $this->assertFalse($operationSuccessful);
350 $path =
'/path/to/your/file';
351 $visibility =
"private";
353 $this->filesystemMock->shouldReceive(
'has')
359 $this->expectExceptionMessage(
"Path \"$path\" not found.");
361 $this->subject->setVisibility($path, $visibility);
370 $path =
'/path/to/your/file';
371 $visibility =
"not valid";
373 $this->filesystemMock->shouldReceive(
'has')
378 $this->expectException(\InvalidArgumentException::class);
379 $this->expectExceptionMessage(
"The access must be 'public' or 'private' but '$visibility' was given.");
381 $this->subject->setVisibility($path, $visibility);
390 $path =
'/path/to/your/file';
391 $visibility =
"private";
393 $this->filesystemMock->shouldReceive(
'has')
398 $this->filesystemMock->shouldReceive(
'getVisibility')
401 ->andReturn($visibility);
403 $actualVisibility = $this->subject->getVisibility($path);
404 $this->assertSame($visibility, $actualVisibility);
413 $path =
'/path/to/your/file';
415 $this->filesystemMock->shouldReceive(
'has')
421 $this->expectExceptionMessage(
"Path \"$path\" not found.");
423 $this->subject->getVisibility($path);
432 $path =
'/path/to/your/file';
434 $this->filesystemMock->shouldReceive(
'has')
439 $this->filesystemMock->shouldReceive(
'getVisibility')
444 $this->expectException(IOException::class);
445 $this->expectExceptionMessage(
"Could not determine visibility for path '$path'.");
447 $this->subject->getVisibility($path);
456 $path =
'/path/to/your/file';
457 $content =
"some awesome content";
459 $this->filesystemMock->shouldReceive(
'write')
461 ->withArgs([$path, $content])
464 $this->subject->write($path, $content);
473 $path =
'/path/to/your/file';
474 $content =
"some awesome content";
476 $this->filesystemMock->shouldReceive(
'write')
478 ->withArgs([$path, $content])
479 ->andThrow(FileExistsException::class);
481 $this->expectException(FileAlreadyExistsException::class);
482 $this->expectExceptionMessage(
"File \"$path\" already exists.");
484 $this->subject->write($path, $content);
493 $path =
'/path/to/your/file';
494 $content =
"some awesome content";
496 $this->filesystemMock->shouldReceive(
'write')
498 ->withArgs([$path, $content])
501 $this->expectException(IOException::class);
502 $this->expectExceptionMessage(
"Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable.");
504 $this->subject->write($path, $content);
513 $path =
'/path/to/your/file';
514 $content =
"some awesome content";
516 $this->filesystemMock->shouldReceive(
'update')
518 ->withArgs([$path, $content])
521 $this->subject->update($path, $content);
530 $path =
'/path/to/your/file';
531 $content =
"some awesome content";
533 $this->filesystemMock->shouldReceive(
'update')
535 ->withArgs([$path, $content])
538 $this->expectException(IOException::class);
539 $this->expectExceptionMessage(
"Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable.");
541 $this->subject->update($path, $content);
550 $path =
'/path/to/your/file';
551 $content =
"some awesome content";
553 $this->filesystemMock->shouldReceive(
'update')
555 ->withArgs([$path, $content])
556 ->andThrow(FileNotFoundException::class);
559 $this->expectExceptionMessage(
"File \"$path\" was not found update failed.");
561 $this->subject->update($path, $content);
570 $path =
'/path/to/your/file';
571 $content =
"some awesome content";
573 $this->filesystemMock->shouldReceive(
'put')
575 ->withArgs([$path, $content])
578 $this->subject->put($path, $content);
587 $path =
'/path/to/your/file';
588 $content =
"some awesome content";
590 $this->filesystemMock->shouldReceive(
'put')
592 ->withArgs([$path, $content])
595 $this->expectException(IOException::class);
596 $this->expectExceptionMessage(
"Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable.");
598 $this->subject->put($path, $content);
607 $path =
'/path/to/your/file';
609 $this->filesystemMock->shouldReceive(
'delete')
614 $this->subject->delete($path);
623 $path =
'/path/to/your/file';
625 $this->filesystemMock->shouldReceive(
'delete')
630 $this->expectException(IOException::class);
631 $this->expectExceptionMessage(
"Could not delete file \"$path\" because a general IO error occurred. Please check that your target is writable.");
633 $this->subject->delete($path);
642 $path =
'/path/to/your/file';
644 $this->filesystemMock->shouldReceive(
'delete')
647 ->andThrow(FileNotFoundException::class);
650 $this->expectExceptionMessage(
"File \"$path\" was not found delete operation failed.");
652 $this->subject->delete($path);
662 $path =
'/path/to/your/file';
663 $content =
"awesome content";
666 $this->subject = Mockery::mock(FlySystemFileAccess::class, [$this->filesystemMock])->makePartial();
669 ->shouldReceive(
'read')
672 ->andReturn($content)
674 ->shouldReceive(
'delete')
678 $this->subject->readAndDelete($path);
688 $destination =
'/dest/path';
690 $this->filesystemMock
691 ->shouldReceive(
'rename')
693 ->withArgs([
$source, $destination])
696 $this->subject->rename(
$source, $destination);
706 $destination =
'/dest/path';
708 $this->filesystemMock
709 ->shouldReceive(
'rename')
711 ->withArgs([
$source, $destination])
712 ->andThrow(FileNotFoundException::class);
715 $this->expectExceptionMessage(
"File \"$source\" not found.");
717 $this->subject->rename(
$source, $destination);
727 $destination =
'/dest/path';
729 $this->filesystemMock
730 ->shouldReceive(
'rename')
732 ->withArgs([
$source, $destination])
733 ->andThrow(FileExistsException::class);
735 $this->expectException(FileAlreadyExistsException::class);
736 $this->expectExceptionMessage(
"File \"$destination\" already exists.");
738 $this->subject->rename(
$source, $destination);
748 $destination =
'/dest/path';
750 $this->filesystemMock
751 ->shouldReceive(
'rename')
753 ->withArgs([
$source, $destination])
756 $this->expectException(IOException::class);
757 $this->expectExceptionMessage(
"Could not move file from \"$source\" to \"$destination\".");
759 $this->subject->rename(
$source, $destination);
768 $sourcePath =
'/path/to/your/source/file';
769 $destinationPath =
'/path/to/your/destination/file';
771 $this->filesystemMock->shouldReceive(
'copy')
773 ->withArgs([$sourcePath, $destinationPath])
776 $this->subject->copy($sourcePath, $destinationPath);
785 $sourcePath =
'/path/to/your/source/file';
786 $destinationPath =
'/path/to/your/destination/file';
788 $this->filesystemMock->shouldReceive(
'copy')
790 ->withArgs([$sourcePath, $destinationPath])
793 $this->expectException(IOException::class);
794 $this->expectExceptionMessage(
"Could not copy file \"$sourcePath\" to destination \"$destinationPath\" because a general IO error occurred. Please check that your destination is writable.");
796 $this->subject->copy($sourcePath, $destinationPath);
805 $sourcePath =
'/path/to/your/source/file';
806 $destinationPath =
'/path/to/your/destination/file';
808 $this->filesystemMock->shouldReceive(
'copy')
810 ->withArgs([$sourcePath, $destinationPath])
811 ->andThrow(FileNotFoundException::class);
814 $this->expectExceptionMessage(
"File source \"$sourcePath\" was not found copy failed.");
816 $this->subject->copy($sourcePath, $destinationPath);
825 $sourcePath =
'/path/to/your/source/file';
826 $destinationPath =
'/path/to/your/destination/file';
828 $this->filesystemMock->shouldReceive(
'copy')
830 ->withArgs([$sourcePath, $destinationPath])
831 ->andThrow(FileExistsException::class);
833 $this->expectException(FileAlreadyExistsException::class);
834 $this->expectExceptionMessage(
"File destination \"$destinationPath\" already exists copy failed.");
836 $this->subject->copy($sourcePath, $destinationPath);
testGetTimestampWhichShouldSucceed()
testUpdateWithAdapterErrorWhichShouldFail()
testGetMimeTypeWhichShouldSucceed()
testSetVisibilityWithInvalidAccessModifierWhichShouldFail()
testWriteWhichShouldSucceed()
testGetVisibilityWithMissingFileWhichShouldFail()
testRenameWithGeneralErrorWhichShouldFail()
Class ChatMainBarProvider .
Class FlySystemFileAccess Fly system file access implementation.
setUp()
Sets up the fixture, for example, open a network connection.
testGetSizeWhichShouldSucceed()
testGetTimestampWithMissingFileWhichShouldFail()
testDeleteWithMissingFileWhichShouldFail()
testCopyWhichShouldSucceed()
testGetSizeWithUnknownAdapterErrorWhichShouldFail()
testPutWithAdapterErrorWhichShouldFail()
testCopyWithMissingFileWhichShouldFail()
testPutWhichShouldSucceed()
testReadWithGeneralFileAccessErrorWhichShouldFail()
testReadWhichShouldSucceed()
testCopyWithAdapterErrorWhichShouldFail()
testUpdateWithMissingFileWhichShouldFail()
testGetMimeTypeWithMissingFileWhichShouldFail()
testRenameWithExistingDestinationWhichShouldFail()
testDeleteWhichShouldSucceed()
testRenameWithMissingSourceWhichShouldFail()
testWriteWithAdapterErrorWhichShouldFail()
testCopyWithExistingDestinationFileWhichShouldFail()
testSetVisibilityThatFailedDueToAdapterFailureWhichShouldFail()
testGetVisibilityWhichShouldSucceed()
testGetTimestampWithUnknownErrorWhichShouldFail()
foreach($mandatory_scripts as $file) $timestamp
testUpdateWhichShouldSucceed()
testGetMimeTypeWithUnknownMimeTypeWhichShouldFail()
testReadWithMissingFileWhichShouldFail()
testSetVisibilityWhichShouldSucceed()
testGetVisibilityWithAdapterErrorWhichShouldFail()
testWriteWithAlreadyExistingFileWhichShouldFail()
Class FlySystemFileAccessTest disabled disabled disabled.
testSetVisibilityWithMissingFileWhichShouldFail()
testReadAndDeleteWhichShouldSucceed()
Maybe a useless test.
testGetSizeWithMissingFileWhichShouldFail()
testRenameWhichShouldSucceed()
testDeleteWithAdapterErrorWhichShouldFail()