52 private \ILIAS\Filesystem\Provider\FlySystem\FlySystemFileAccess
$subject;
63 protected function setUp(): void
67 $this->filesystemMock = Mockery::mock(FilesystemOperator::class);
68 $this->adapterMock = Mockery::mock(FilesystemAdapter::class);
74 $file_content =
'Test file content.';
75 $path =
'/path/to/your/file';
77 $this->filesystemMock->shouldReceive(
'has')
79 ->with(ltrim(
$path,
'/'))
82 $this->filesystemMock->shouldReceive(
'read')
83 ->with(ltrim(
$path,
'/'))
85 ->andReturn($file_content);
88 $actualContent = $this->subject->read(
$path);
89 $this->assertSame($file_content, $actualContent);
94 $path =
'/path/to/your/file';
96 $this->filesystemMock->shouldReceive(
'has')
98 ->with(ltrim(
$path,
'/'))
101 $this->filesystemMock->shouldReceive(
'read')
102 ->with(ltrim(
$path,
'/'))
107 $this->expectException(IOException::class);
108 $this->expectExceptionMessage(
'File "' . ltrim(
$path,
'/') .
'" not found.');
109 $actualContent = $this->subject->read(
$path);
115 $path =
'/path/to/your/file';
117 $this->filesystemMock->shouldReceive(
'has')
119 ->with(ltrim(
$path,
'/'))
122 $this->filesystemMock->shouldReceive(
'read')
126 $this->expectException(IOException::class);
127 $this->expectExceptionMessage(
'File "' . ltrim(
$path,
'/') .
'" not found.');
128 $actualContent = $this->subject->read(
$path);
133 $mimeType =
'image/jpeg';
134 $this->filesystemMock->shouldReceive(
'mimeType')
136 ->andReturn($mimeType);
138 $actualMimeType = $this->subject->getMimeType(
'/path/to/your/file');
139 $this->assertSame($mimeType, $actualMimeType);
144 $content =
'Test file content.';
145 $this->filesystemMock->shouldReceive(
'has')
148 $this->filesystemMock->shouldReceive(
'write')
149 ->with(
'/path/to/your/file', $content)
153 $this->subject->put(
'/path/to/your/file', $content);
158 $content =
'Test file content.';
159 $this->filesystemMock->shouldReceive(
'has')
163 $this->filesystemMock->shouldReceive(
'write')
164 ->with(
'/path/to/your/file', $content)
168 $this->subject->put(
'/path/to/your/file', $content);
174 $path =
'/path/to/your/file';
175 $this->filesystemMock->shouldReceive(
'mimeType')
180 $this->expectException(IOException::class);
181 $this->expectExceptionMessage(
"Could not determine the MIME type of the file \"$path\".");
183 $this->subject->getMimeType(
$path);
188 $path =
'/path/to/your/file';
189 $this->filesystemMock->shouldReceive(
'mimeType')
192 ->andThrow(UnableToRetrieveMetadata::class);
194 $this->expectException(IOException::class);
195 $this->expectExceptionMessage(
"File \"$path\" not found.");
197 $this->subject->getMimeType(
$path);
204 $this->filesystemMock
205 ->shouldReceive(
'lastModified')
209 $actualTimestamp = $this->subject->getTimestamp(
'/path/to/your/file');
227 $path =
'/path/to/your/file';
228 $this->filesystemMock
229 ->shouldReceive(
'lastModified')
232 ->andThrow(UnableToRetrieveMetadata::class);
234 $this->expectException(IOException::class);
235 $this->expectExceptionMessage(
"Could not lookup timestamp of the file \"$path\".");
237 $this->subject->getTimestamp(
$path);
242 $path =
'/path/to/your/file';
243 $this->filesystemMock
244 ->shouldReceive(
'lastModified')
247 ->andThrow(UnableToReadFile::class);
249 $this->expectException(IOException::class);
250 $this->expectExceptionMessage(
"File \"$path\" not found.");
252 $this->subject->getTimestamp(
$path);
260 $this->filesystemMock->shouldReceive(
'fileSize')
262 ->andReturn($rawSize);
264 $actualSize = $this->subject->getSize(
'/path/to/your/file',
DataSize::KiB);
265 $this->assertSame($size->getSize(), $actualSize->getSize(),
'');
270 $path =
'/path/to/your/file';
271 $this->filesystemMock
272 ->shouldReceive(
'fileSize')
275 ->andThrow(UnableToRetrieveMetadata::class);
277 $this->expectException(IOException::class);
278 $this->expectExceptionMessage(
"File \"$path\" not found.");
285 $path =
'/path/to/your/file';
286 $this->filesystemMock
287 ->shouldReceive(
'fileSize')
290 ->andThrow(UnableToRetrieveMetadata::class);
292 $this->expectException(IOException::class);
293 $this->expectExceptionMessage(
"File \"$path\" not found.");
300 $path =
'/path/to/your/file';
301 $visibility =
"private";
303 $this->filesystemMock->shouldReceive(
'has')
308 $this->filesystemMock->shouldReceive(
'setVisibility')
310 ->withArgs([
$path, $visibility])
313 $operationSuccessful = $this->subject->setVisibility(
$path, $visibility);
314 $this->assertTrue($operationSuccessful);
319 $path =
'/path/to/your/file';
320 $visibility =
"private";
322 $this->filesystemMock->shouldReceive(
'has')
327 $this->filesystemMock->shouldReceive(
'setVisibility')
329 ->withArgs([
$path, $visibility])
330 ->andThrow(UnableToSetVisibility::class);
332 $operationSuccessful = $this->subject->setVisibility(
$path, $visibility);
333 $this->assertFalse($operationSuccessful);
342 $path =
'/path/to/your/file';
343 $visibility =
"private";
345 $this->filesystemMock->shouldReceive(
'has')
351 $this->expectExceptionMessage(
"Path \"$path\" not found.");
353 $this->subject->setVisibility(
$path, $visibility);
362 $path =
'/path/to/your/file';
363 $visibility =
"not valid";
365 $this->filesystemMock->shouldReceive(
'has')
370 $this->expectException(\InvalidArgumentException::class);
371 $this->expectExceptionMessage(
"The access must be 'public' or 'private' but '$visibility' was given.");
373 $this->subject->setVisibility(
$path, $visibility);
382 $path =
'/path/to/your/file';
383 $visibility =
"private";
385 $this->filesystemMock->shouldReceive(
'has')
390 $this->filesystemMock->shouldReceive(
'getVisibility')
393 ->andReturn($visibility);
395 $actualVisibility = $this->subject->getVisibility(
$path);
396 $this->assertSame($visibility, $actualVisibility);
405 $path =
'/path/to/your/file';
407 $this->filesystemMock->shouldReceive(
'has')
413 $this->expectExceptionMessage(
"Path \"$path\" not found.");
415 $this->subject->getVisibility(
$path);
424 $path =
'/path/to/your/file';
426 $this->filesystemMock->shouldReceive(
'has')
431 $this->filesystemMock->shouldReceive(
'getVisibility')
436 $this->expectException(IOException::class);
437 $this->expectExceptionMessage(
"Could not determine visibility for path '$path'.");
439 $this->subject->getVisibility(
$path);
448 $path =
'/path/to/your/file';
449 $content =
"some awesome content";
451 $this->filesystemMock
452 ->shouldReceive(
'has')
457 ->shouldReceive(
'write')
459 ->withArgs([
$path, $content]);
461 $this->subject->write(
$path, $content);
470 $path =
'/path/to/your/file';
471 $content =
"some awesome content";
473 $this->filesystemMock
474 ->shouldReceive(
'has')
478 ->shouldReceive(
'write')
480 ->withArgs([
$path, $content])
481 ->andThrow(UnableToWriteFile::class);
483 $this->expectException(FileAlreadyExistsException::class);
484 $this->expectExceptionMessage(
"File \"$path\" already exists.");
486 $this->subject->write(
$path, $content);
495 $path =
'/path/to/your/file';
496 $content =
"some awesome content";
498 $this->filesystemMock
499 ->shouldReceive(
'has')
504 ->shouldReceive(
'write')
506 ->withArgs([
$path, $content])
507 ->andThrow(UnableToWriteFile::class);
509 $this->expectException(IOException::class);
510 $this->expectExceptionMessage(
511 "Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable." 514 $this->subject->write(
$path, $content);
523 $path =
'/path/to/your/file';
524 $content =
"some awesome content";
526 $this->filesystemMock->shouldReceive(
'write')
528 ->withArgs([
$path, $content])
531 $this->subject->update(
$path, $content);
540 $path =
'/path/to/your/file';
541 $content =
"some awesome content";
543 $this->filesystemMock->shouldReceive(
'write')
545 ->withArgs([
$path, $content])
546 ->andThrow(UnableToWriteFile::class);
548 $this->expectException(IOException::class);
549 $this->expectExceptionMessage(
550 "Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable." 553 $this->subject->update(
$path, $content);
562 $path =
'/path/to/your/file';
563 $content =
"some awesome content";
565 $this->filesystemMock
566 ->shouldReceive(
'write')
568 ->withArgs([
$path, $content])
569 ->andThrow(UnableToWriteFile::class);
571 $this->expectException(IOException::class);
572 $this->expectExceptionMessage(
573 "Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable." 576 $this->subject->update(
$path, $content);
585 $path =
'/path/to/your/file';
587 $this->filesystemMock->shouldReceive(
'delete')
592 $this->subject->delete(
$path);
601 $path =
'/path/to/your/file';
603 $this->filesystemMock->shouldReceive(
'delete')
606 ->andThrow(UnableToDeleteFile::class);
608 $this->expectException(IOException::class);
609 $this->expectExceptionMessage(
610 "Could not delete file \"$path\" because a general IO error occurred. Please check that your target is writable." 613 $this->subject->delete(
$path);
622 $path =
'/path/to/your/file';
624 $this->filesystemMock->shouldReceive(
'delete')
627 ->andThrow(UnableToRetrieveMetadata::class);
630 $this->expectExceptionMessage(
"File \"$path\" was not found delete operation failed.");
632 $this->subject->delete(
$path);
642 $path =
'/path/to/your/file';
643 $content =
"awesome content";
646 $this->subject = Mockery::mock(FlySystemFileAccess::class, [$this->filesystemMock])->makePartial();
649 ->shouldReceive(
'read')
652 ->andReturn($content)
654 ->shouldReceive(
'delete')
658 $this->subject->readAndDelete(
$path);
667 $source =
'/source/path';
668 $destination =
'/dest/path';
670 $this->filesystemMock
671 ->shouldReceive(
'has')
676 ->shouldReceive(
'move')
678 ->withArgs([$source, $destination])
681 $this->subject->rename($source, $destination);
690 $source =
'/source/path';
691 $destination =
'/dest/path';
693 $this->filesystemMock
694 ->shouldReceive(
'has')
699 ->shouldReceive(
'move')
701 ->withArgs([$source, $destination])
702 ->andThrow(UnableToRetrieveMetadata::class);
705 $this->expectExceptionMessage(
"File \"$source\" not found.");
707 $this->subject->rename($source, $destination);
716 $source =
'/source/path';
717 $destination =
'/dest/path';
719 $this->filesystemMock
720 ->shouldReceive(
'has')
725 ->shouldReceive(
'move')
727 ->withArgs([$source, $destination])
728 ->andThrow(UnableToMoveFile::class);
730 $this->expectException(IOException::class);
731 $this->expectExceptionMessage(
"File \"$destination\" already exists.");
733 $this->subject->rename($source, $destination);
742 $source =
'/source/path';
743 $destination =
'/dest/path';
745 $this->filesystemMock
746 ->shouldReceive(
'has')
751 ->shouldReceive(
'move')
753 ->withArgs([$source, $destination])
754 ->andThrow(UnableToMoveFile::class);
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
772 ->shouldReceive(
'has')
774 ->with($destinationPath)
777 ->shouldReceive(
'copy')
779 ->withArgs([$sourcePath, $destinationPath])
782 $this->subject->copy($sourcePath, $destinationPath);
791 $sourcePath =
'/path/to/your/source/file';
792 $destinationPath =
'/path/to/your/destination/file';
794 $this->filesystemMock
795 ->shouldReceive(
'has')
797 ->with($destinationPath)
800 ->shouldReceive(
'copy')
802 ->withArgs([$sourcePath, $destinationPath])
803 ->andThrow(UnableToCopyFile::class);
805 $this->expectException(IOException::class);
806 $this->expectExceptionMessage(
807 "Could not copy file \"$sourcePath\" to destination \"$destinationPath\" because a general IO error occurred. Please check that your destination is writable." 810 $this->subject->copy($sourcePath, $destinationPath);
819 $sourcePath =
'/path/to/your/source/file';
820 $destinationPath =
'/path/to/your/destination/file';
822 $this->filesystemMock
823 ->shouldReceive(
'has')
825 ->with($destinationPath)
828 ->shouldReceive(
'copy')
830 ->withArgs([$sourcePath, $destinationPath])
831 ->andThrow(UnableToRetrieveMetadata::class);
834 $this->expectExceptionMessage(
"File source \"$sourcePath\" was not found copy failed.");
836 $this->subject->copy($sourcePath, $destinationPath);
845 $sourcePath =
'/path/to/your/source/file';
846 $destinationPath =
'/path/to/your/destination/file';
848 $this->filesystemMock
849 ->shouldReceive(
'has')
851 ->with($destinationPath)
854 ->shouldReceive(
'copy')
856 ->withArgs([$sourcePath, $destinationPath])
857 ->andThrow(UnableToCopyFile::class);
859 $this->expectException(FileAlreadyExistsException::class);
860 $this->expectExceptionMessage(
"File \"$destinationPath\" already exists.");
862 $this->subject->copy($sourcePath, $destinationPath);
testGetTimestampWhichShouldSucceed()
testUpdateWithAdapterErrorWhichShouldFail()
testGetMimeTypeWhichShouldSucceed()
testSetVisibilityWithInvalidAccessModifierWhichShouldFail()
testWriteWhichShouldSucceed()
testGetVisibilityWithMissingFileWhichShouldFail()
testRenameWithGeneralErrorWhichShouldFail()
Interface Observer Contains several chained tasks and infos about them.
This class provides the data size with additional information to remove the work to calculate the siz...
Fly system file access implementation.
setUp()
Sets up the fixture, for example, open a network connection.
testGetSizeWhichShouldSucceed()
testGetTimestampWithMissingFileWhichShouldFail()
testDeleteWithMissingFileWhichShouldFail()
testPutContentExistingFile()
testCopyWhichShouldSucceed()
testGetSizeWithUnknownAdapterErrorWhichShouldFail()
League Flysystem Filesystem Mockery MockInterface $filesystemMock
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testCopyWithMissingFileWhichShouldFail()
testReadWithGeneralFileAccessErrorWhichShouldFail()
testReadWhichShouldSucceed()
testCopyWithAdapterErrorWhichShouldFail()
testUpdateWithMissingFileWhichShouldFail()
testGetMimeTypeWithMissingFileWhichShouldFail()
testPutContentNonExistingFile()
testRenameWithExistingDestinationWhichShouldFail()
testDeleteWhichShouldSucceed()
testRenameWithMissingSourceWhichShouldFail()
testWriteWithAdapterErrorWhichShouldFail()
testCopyWithExistingDestinationFileWhichShouldFail()
testSetVisibilityThatFailedDueToAdapterFailureWhichShouldFail()
ILIAS Filesystem Provider FlySystem FlySystemFileAccess $subject
testGetVisibilityWhichShouldSucceed()
Mockery LegacyMockInterface $adapterMock
testGetTimestampWithUnknownErrorWhichShouldFail()
foreach($mandatory_scripts as $file) $timestamp
testUpdateWhichShouldSucceed()
testGetMimeTypeWithUnknownMimeTypeWhichShouldFail()
testReadWithMissingFileWhichShouldFail()
testSetVisibilityWhichShouldSucceed()
testGetVisibilityWithAdapterErrorWhichShouldFail()
testWriteWithAlreadyExistingFileWhichShouldFail()
testSetVisibilityWithMissingFileWhichShouldFail()
testReadAndDeleteWhichShouldSucceed()
Maybe a useless test.
testGetSizeWithMissingFileWhichShouldFail()
testRenameWhichShouldSucceed()
testDeleteWithAdapterErrorWhichShouldFail()