59 protected function setUp(): void
63 $this->filesystemMock = Mockery::mock(FilesystemOperator::class);
64 $adapterMock = Mockery::mock(FilesystemAdapter::class);
70 $file_content =
'Test file content.';
71 $path =
'/path/to/your/file';
73 $this->filesystemMock->shouldReceive(
'has')
75 ->with(ltrim(
$path,
'/'))
78 $this->filesystemMock->shouldReceive(
'read')
79 ->with(ltrim(
$path,
'/'))
81 ->andReturn($file_content);
84 $actualContent = $this->subject->read(
$path);
85 $this->assertSame($file_content, $actualContent);
90 $path =
'/path/to/your/file';
92 $this->filesystemMock->shouldReceive(
'has')
94 ->with(ltrim(
$path,
'/'))
97 $this->filesystemMock->shouldReceive(
'read')
98 ->with(ltrim(
$path,
'/'))
103 $this->expectException(IOException::class);
104 $this->expectExceptionMessage(
'File "' . ltrim(
$path,
'/') .
'" not found.');
105 $actualContent = $this->subject->read(
$path);
111 $path =
'/path/to/your/file';
113 $this->filesystemMock->shouldReceive(
'has')
115 ->with(ltrim(
$path,
'/'))
118 $this->filesystemMock->shouldReceive(
'read')
122 $this->expectException(IOException::class);
123 $this->expectExceptionMessage(
'File "' . ltrim(
$path,
'/') .
'" not found.');
124 $actualContent = $this->subject->read(
$path);
129 $mimeType =
'image/jpeg';
130 $this->filesystemMock->shouldReceive(
'mimeType')
132 ->andReturn($mimeType);
134 $actualMimeType = $this->subject->getMimeType(
'/path/to/your/file');
135 $this->assertSame($mimeType, $actualMimeType);
140 $content =
'Test file content.';
141 $this->filesystemMock->shouldReceive(
'has')
144 $this->filesystemMock->shouldReceive(
'write')
145 ->with(
'/path/to/your/file', $content)
149 $this->subject->put(
'/path/to/your/file', $content);
154 $content =
'Test file content.';
155 $this->filesystemMock->shouldReceive(
'has')
159 $this->filesystemMock->shouldReceive(
'write')
160 ->with(
'/path/to/your/file', $content)
164 $this->subject->put(
'/path/to/your/file', $content);
170 $path =
'/path/to/your/file';
171 $this->filesystemMock->shouldReceive(
'mimeType')
176 $this->expectException(IOException::class);
177 $this->expectExceptionMessage(
"Could not determine the MIME type of the file \"$path\".");
179 $this->subject->getMimeType(
$path);
184 $path =
'/path/to/your/file';
185 $this->filesystemMock->shouldReceive(
'mimeType')
188 ->andThrow(UnableToRetrieveMetadata::class);
190 $this->expectException(IOException::class);
191 $this->expectExceptionMessage(
"File \"$path\" not found.");
193 $this->subject->getMimeType(
$path);
200 $this->filesystemMock
201 ->shouldReceive(
'lastModified')
205 $actualTimestamp = $this->subject->getTimestamp(
'/path/to/your/file');
223 $path =
'/path/to/your/file';
224 $this->filesystemMock
225 ->shouldReceive(
'lastModified')
228 ->andThrow(UnableToRetrieveMetadata::class);
230 $this->expectException(IOException::class);
231 $this->expectExceptionMessage(
"Could not lookup timestamp of the file \"$path\".");
233 $this->subject->getTimestamp(
$path);
238 $path =
'/path/to/your/file';
239 $this->filesystemMock
240 ->shouldReceive(
'lastModified')
243 ->andThrow(UnableToReadFile::class);
245 $this->expectException(IOException::class);
246 $this->expectExceptionMessage(
"File \"$path\" not found.");
248 $this->subject->getTimestamp(
$path);
256 $this->filesystemMock->shouldReceive(
'fileSize')
258 ->andReturn($rawSize);
260 $actualSize = $this->subject->getSize(
'/path/to/your/file',
DataSize::KiB);
261 $this->assertSame($size->getSize(), $actualSize->getSize(),
'');
266 $path =
'/path/to/your/file';
267 $this->filesystemMock
268 ->shouldReceive(
'fileSize')
271 ->andThrow(UnableToRetrieveMetadata::class);
273 $this->expectException(IOException::class);
274 $this->expectExceptionMessage(
"File \"$path\" not found.");
281 $path =
'/path/to/your/file';
282 $this->filesystemMock
283 ->shouldReceive(
'fileSize')
286 ->andThrow(UnableToRetrieveMetadata::class);
288 $this->expectException(IOException::class);
289 $this->expectExceptionMessage(
"File \"$path\" not found.");
296 $path =
'/path/to/your/file';
297 $visibility =
"private";
299 $this->filesystemMock->shouldReceive(
'has')
304 $this->filesystemMock->shouldReceive(
'setVisibility')
306 ->withArgs([
$path, $visibility])
309 $operationSuccessful = $this->subject->setVisibility(
$path, $visibility);
310 $this->assertTrue($operationSuccessful);
315 $path =
'/path/to/your/file';
316 $visibility =
"private";
318 $this->filesystemMock->shouldReceive(
'has')
323 $this->filesystemMock->shouldReceive(
'setVisibility')
325 ->withArgs([
$path, $visibility])
326 ->andThrow(UnableToSetVisibility::class);
328 $operationSuccessful = $this->subject->setVisibility(
$path, $visibility);
329 $this->assertFalse($operationSuccessful);
336 $path =
'/path/to/your/file';
337 $visibility =
"private";
339 $this->filesystemMock->shouldReceive(
'has')
344 $this->expectException(FileNotFoundException::class);
345 $this->expectExceptionMessage(
"Path \"$path\" not found.");
347 $this->subject->setVisibility(
$path, $visibility);
354 $path =
'/path/to/your/file';
355 $visibility =
"not valid";
357 $this->filesystemMock->shouldReceive(
'has')
362 $this->expectException(\InvalidArgumentException::class);
363 $this->expectExceptionMessage(
"The access must be 'public' or 'private' but '$visibility' was given.");
365 $this->subject->setVisibility(
$path, $visibility);
372 $path =
'/path/to/your/file';
373 $visibility =
"private";
375 $this->filesystemMock->shouldReceive(
'has')
380 $this->filesystemMock->shouldReceive(
'getVisibility')
383 ->andReturn($visibility);
385 $actualVisibility = $this->subject->getVisibility(
$path);
386 $this->assertSame($visibility, $actualVisibility);
393 $path =
'/path/to/your/file';
395 $this->filesystemMock->shouldReceive(
'has')
400 $this->expectException(FileNotFoundException::class);
401 $this->expectExceptionMessage(
"Path \"$path\" not found.");
403 $this->subject->getVisibility(
$path);
410 $path =
'/path/to/your/file';
412 $this->filesystemMock->shouldReceive(
'has')
417 $this->filesystemMock->shouldReceive(
'getVisibility')
422 $this->expectException(IOException::class);
423 $this->expectExceptionMessage(
"Could not determine visibility for path '$path'.");
425 $this->subject->getVisibility(
$path);
432 $path =
'/path/to/your/file';
433 $content =
"some awesome content";
435 $this->filesystemMock
436 ->shouldReceive(
'has')
441 ->shouldReceive(
'write')
443 ->withArgs([
$path, $content]);
445 $this->subject->write(
$path, $content);
452 $path =
'/path/to/your/file';
453 $content =
"some awesome content";
455 $this->filesystemMock
456 ->shouldReceive(
'has')
460 ->shouldReceive(
'write')
462 ->withArgs([
$path, $content])
463 ->andThrow(UnableToWriteFile::class);
465 $this->expectException(FileAlreadyExistsException::class);
466 $this->expectExceptionMessage(
"File \"$path\" already exists.");
468 $this->subject->write(
$path, $content);
475 $path =
'/path/to/your/file';
476 $content =
"some awesome content";
478 $this->filesystemMock
479 ->shouldReceive(
'has')
484 ->shouldReceive(
'write')
486 ->withArgs([
$path, $content])
487 ->andThrow(UnableToWriteFile::class);
489 $this->expectException(IOException::class);
490 $this->expectExceptionMessage(
491 "Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable." 494 $this->subject->write(
$path, $content);
501 $path =
'/path/to/your/file';
502 $content =
"some awesome content";
504 $this->filesystemMock->shouldReceive(
'write')
506 ->withArgs([
$path, $content])
509 $this->subject->update(
$path, $content);
516 $path =
'/path/to/your/file';
517 $content =
"some awesome content";
519 $this->filesystemMock->shouldReceive(
'write')
521 ->withArgs([
$path, $content])
522 ->andThrow(UnableToWriteFile::class);
524 $this->expectException(IOException::class);
525 $this->expectExceptionMessage(
526 "Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable." 529 $this->subject->update(
$path, $content);
536 $path =
'/path/to/your/file';
537 $content =
"some awesome content";
539 $this->filesystemMock
540 ->shouldReceive(
'write')
542 ->withArgs([
$path, $content])
543 ->andThrow(UnableToWriteFile::class);
545 $this->expectException(IOException::class);
546 $this->expectExceptionMessage(
547 "Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable." 550 $this->subject->update(
$path, $content);
557 $path =
'/path/to/your/file';
559 $this->filesystemMock->shouldReceive(
'delete')
564 $this->subject->delete(
$path);
571 $path =
'/path/to/your/file';
573 $this->filesystemMock->shouldReceive(
'delete')
576 ->andThrow(UnableToDeleteFile::class);
578 $this->expectException(IOException::class);
579 $this->expectExceptionMessage(
580 "Could not delete file \"$path\" because a general IO error occurred. Please check that your target is writable." 583 $this->subject->delete(
$path);
590 $path =
'/path/to/your/file';
592 $this->filesystemMock->shouldReceive(
'delete')
595 ->andThrow(UnableToRetrieveMetadata::class);
597 $this->expectException(FileNotFoundException::class);
598 $this->expectExceptionMessage(
"File \"$path\" was not found delete operation failed.");
600 $this->subject->delete(
$path);
607 $path =
'/path/to/your/file';
608 $content =
"awesome content";
611 $this->subject = Mockery::mock(FlySystemFileAccess::class, [$this->filesystemMock])->makePartial();
614 ->shouldReceive(
'read')
617 ->andReturn($content)
619 ->shouldReceive(
'delete')
623 $this->subject->readAndDelete(
$path);
630 $source =
'/source/path';
631 $destination =
'/dest/path';
633 $this->filesystemMock
634 ->shouldReceive(
'has')
639 ->shouldReceive(
'move')
641 ->withArgs([$source, $destination])
644 $this->subject->rename($source, $destination);
651 $source =
'/source/path';
652 $destination =
'/dest/path';
654 $this->filesystemMock
655 ->shouldReceive(
'has')
660 ->shouldReceive(
'move')
662 ->withArgs([$source, $destination])
663 ->andThrow(UnableToRetrieveMetadata::class);
665 $this->expectException(FileNotFoundException::class);
666 $this->expectExceptionMessage(
"File \"$source\" not found.");
668 $this->subject->rename($source, $destination);
675 $source =
'/source/path';
676 $destination =
'/dest/path';
678 $this->filesystemMock
679 ->shouldReceive(
'has')
684 ->shouldReceive(
'move')
686 ->withArgs([$source, $destination])
687 ->andThrow(UnableToMoveFile::class);
689 $this->expectException(IOException::class);
690 $this->expectExceptionMessage(
"File \"$destination\" already exists.");
692 $this->subject->rename($source, $destination);
699 $source =
'/source/path';
700 $destination =
'/dest/path';
702 $this->filesystemMock
703 ->shouldReceive(
'has')
708 ->shouldReceive(
'move')
710 ->withArgs([$source, $destination])
711 ->andThrow(UnableToMoveFile::class);
713 $this->expectException(IOException::class);
714 $this->expectExceptionMessage(
"Could not move file from \"$source\" to \"$destination\".");
716 $this->subject->rename($source, $destination);
723 $sourcePath =
'/path/to/your/source/file';
724 $destinationPath =
'/path/to/your/destination/file';
726 $this->filesystemMock
727 ->shouldReceive(
'has')
729 ->with($destinationPath)
732 ->shouldReceive(
'copy')
734 ->withArgs([$sourcePath, $destinationPath])
737 $this->subject->copy($sourcePath, $destinationPath);
744 $sourcePath =
'/path/to/your/source/file';
745 $destinationPath =
'/path/to/your/destination/file';
747 $this->filesystemMock
748 ->shouldReceive(
'has')
750 ->with($destinationPath)
753 ->shouldReceive(
'copy')
755 ->withArgs([$sourcePath, $destinationPath])
756 ->andThrow(UnableToCopyFile::class);
758 $this->expectException(IOException::class);
759 $this->expectExceptionMessage(
760 "Could not copy file \"$sourcePath\" to destination \"$destinationPath\" because a general IO error occurred. Please check that your destination is writable." 763 $this->subject->copy($sourcePath, $destinationPath);
770 $sourcePath =
'/path/to/your/source/file';
771 $destinationPath =
'/path/to/your/destination/file';
773 $this->filesystemMock
774 ->shouldReceive(
'has')
776 ->with($destinationPath)
779 ->shouldReceive(
'copy')
781 ->withArgs([$sourcePath, $destinationPath])
782 ->andThrow(UnableToRetrieveMetadata::class);
784 $this->expectException(FileNotFoundException::class);
785 $this->expectExceptionMessage(
"File source \"$sourcePath\" was not found copy failed.");
787 $this->subject->copy($sourcePath, $destinationPath);
794 $sourcePath =
'/path/to/your/source/file';
795 $destinationPath =
'/path/to/your/destination/file';
797 $this->filesystemMock
798 ->shouldReceive(
'has')
800 ->with($destinationPath)
803 ->shouldReceive(
'copy')
805 ->withArgs([$sourcePath, $destinationPath])
806 ->andThrow(UnableToCopyFile::class);
808 $this->expectException(FileAlreadyExistsException::class);
809 $this->expectExceptionMessage(
"File \"$destinationPath\" already exists.");
811 $this->subject->copy($sourcePath, $destinationPath);
testGetTimestampWhichShouldSucceed()
testUpdateWithAdapterErrorWhichShouldFail()
testGetMimeTypeWhichShouldSucceed()
testSetVisibilityWithInvalidAccessModifierWhichShouldFail()
testWriteWhichShouldSucceed()
testGetVisibilityWithMissingFileWhichShouldFail()
testRenameWithGeneralErrorWhichShouldFail()
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()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testCopyWithMissingFileWhichShouldFail()
testReadWithGeneralFileAccessErrorWhichShouldFail()
testReadWhichShouldSucceed()
testCopyWithAdapterErrorWhichShouldFail()
testUpdateWithMissingFileWhichShouldFail()
testGetMimeTypeWithMissingFileWhichShouldFail()
Filesystem MockInterface $filesystemMock
testPutContentNonExistingFile()
testRenameWithExistingDestinationWhichShouldFail()
testDeleteWhichShouldSucceed()
testRenameWithMissingSourceWhichShouldFail()
testWriteWithAdapterErrorWhichShouldFail()
testCopyWithExistingDestinationFileWhichShouldFail()
testSetVisibilityThatFailedDueToAdapterFailureWhichShouldFail()
testGetVisibilityWhichShouldSucceed()
testGetTimestampWithUnknownErrorWhichShouldFail()
foreach($mandatory_scripts as $file) $timestamp
testUpdateWhichShouldSucceed()
testGetMimeTypeWithUnknownMimeTypeWhichShouldFail()
testReadWithMissingFileWhichShouldFail()
testSetVisibilityWhichShouldSucceed()
testGetVisibilityWithAdapterErrorWhichShouldFail()
testWriteWithAlreadyExistingFileWhichShouldFail()
FlySystemFileAccess $subject
testSetVisibilityWithMissingFileWhichShouldFail()
testReadAndDeleteWhichShouldSucceed()
testGetSizeWithMissingFileWhichShouldFail()
testRenameWhichShouldSucceed()
testDeleteWithAdapterErrorWhichShouldFail()