8use League\Flysystem\FileExistsException;
9use League\Flysystem\FileNotFoundException;
10use League\Flysystem\Filesystem;
11use League\Flysystem\FilesystemInterface;
13use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
14use Mockery\MockInterface;
15use PHPUnit\Framework\TestCase;
16use League\Flysystem\AdapterInterface;
41 use MockeryPHPUnitIntegration;
43 private \ILIAS\Filesystem\Provider\FlySystem\FlySystemFileAccess
$subject;
57 protected function setUp(): void
61 $this->filesystemMock = Mockery::mock(FilesystemInterface::class);
62 $this->adapterMock = Mockery::mock(AdapterInterface::class);
72 $fileContent =
'Test file content.';
74 $this->adapterMock->shouldReceive(
'read')
76 ->andReturn([
'contents' => $fileContent]);
78 $this->adapterMock->shouldReceive(
'has')
82 $this->filesystemMock->shouldReceive(
'getAdapter')
84 ->andReturn($this->adapterMock);
86 $actualContent = $this->subject->read(
'/path/to/your/file');
87 $this->assertSame($fileContent, $actualContent);
96 $path =
'path/to/your/file';
98 $this->adapterMock->shouldReceive(
'has')
102 $this->adapterMock->shouldReceive(
'read')
104 ->andReturn([
'contents' =>
false]);
106 $this->filesystemMock->shouldReceive(
'getAdapter')
108 ->andReturn($this->adapterMock);
110 $this->expectException(IOException::class);
111 $this->expectExceptionMessage(
"Could not access the file \"$path\".");
113 $this->subject->read(
$path);
122 $path =
'path/to/your/file';
124 $this->adapterMock->shouldReceive(
'has')
128 $this->filesystemMock->shouldReceive(
'getAdapter')
130 ->andReturn($this->adapterMock);
132 $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
133 $this->expectExceptionMessage(
"File \"$path\" not found.");
135 $this->subject->read(
'/' .
$path);
144 $mimeType =
'image/jpeg';
145 $this->filesystemMock->shouldReceive(
'getMimetype')
147 ->andReturn($mimeType);
149 $actualMimeType = $this->subject->getMimeType(
'/path/to/your/file');
150 $this->assertSame($mimeType, $actualMimeType);
159 $path =
'/path/to/your/file';
160 $this->filesystemMock->shouldReceive(
'getMimetype')
165 $this->expectException(IOException::class);
166 $this->expectExceptionMessage(
"Could not determine the MIME type of the file \"$path\".");
168 $this->subject->getMimeType(
$path);
177 $path =
'/path/to/your/file';
178 $this->filesystemMock->shouldReceive(
'getMimetype')
181 ->andThrow(FileNotFoundException::class);
183 $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
184 $this->expectExceptionMessage(
"File \"$path\" not found.");
186 $this->subject->getMimeType(
$path);
196 $this->filesystemMock->shouldReceive(
'getTimestamp')
200 $actualTimestamp = $this->subject->getTimestamp(
'/path/to/your/file');
213 $this->assertEquals(
new \DateTime(
$timestamp), $actualTimestamp);
222 $path =
'/path/to/your/file';
223 $this->filesystemMock->shouldReceive(
'getTimestamp')
228 $this->expectException(IOException::class);
229 $this->expectExceptionMessage(
"Could not lookup timestamp of the file \"$path\".");
231 $this->subject->getTimestamp(
$path);
240 $path =
'/path/to/your/file';
241 $this->filesystemMock->shouldReceive(
'getTimestamp')
244 ->andThrow(FileNotFoundException::class);
246 $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
247 $this->expectExceptionMessage(
"File \"$path\" not found.");
249 $this->subject->getTimestamp(
$path);
262 $this->filesystemMock->shouldReceive(
'getSize')
264 ->andReturn($rawSize);
266 $actualSize = $this->subject->getSize(
'/path/to/your/file',
DataSize::KiB);
267 $this->assertSame($size->getSize(), $actualSize->getSize(),
'', $delta);
276 $path =
'/path/to/your/file';
277 $this->filesystemMock->shouldReceive(
'getSize')
282 $this->expectException(IOException::class);
283 $this->expectExceptionMessage(
"Could not calculate the file size of the file \"$path\".");
294 $path =
'/path/to/your/file';
295 $this->filesystemMock->shouldReceive(
'getSize')
298 ->andThrow(FileNotFoundException::class);
300 $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
301 $this->expectExceptionMessage(
"File \"$path\" not found.");
312 $path =
'/path/to/your/file';
313 $visibility =
"private";
315 $this->filesystemMock->shouldReceive(
'has')
320 $this->filesystemMock->shouldReceive(
'setVisibility')
322 ->withArgs([
$path, $visibility])
325 $operationSuccessful = $this->subject->setVisibility(
$path, $visibility);
326 $this->assertTrue($operationSuccessful);
335 $path =
'/path/to/your/file';
336 $visibility =
"private";
338 $this->filesystemMock->shouldReceive(
'has')
343 $this->filesystemMock->shouldReceive(
'setVisibility')
345 ->withArgs([
$path, $visibility])
348 $operationSuccessful = $this->subject->setVisibility(
$path, $visibility);
349 $this->assertFalse($operationSuccessful);
358 $path =
'/path/to/your/file';
359 $visibility =
"private";
361 $this->filesystemMock->shouldReceive(
'has')
366 $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
367 $this->expectExceptionMessage(
"Path \"$path\" not found.");
369 $this->subject->setVisibility(
$path, $visibility);
378 $path =
'/path/to/your/file';
379 $visibility =
"not valid";
381 $this->filesystemMock->shouldReceive(
'has')
386 $this->expectException(\InvalidArgumentException::class);
387 $this->expectExceptionMessage(
"The access must be 'public' or 'private' but '$visibility' was given.");
389 $this->subject->setVisibility(
$path, $visibility);
398 $path =
'/path/to/your/file';
399 $visibility =
"private";
401 $this->filesystemMock->shouldReceive(
'has')
406 $this->filesystemMock->shouldReceive(
'getVisibility')
409 ->andReturn($visibility);
411 $actualVisibility = $this->subject->getVisibility(
$path);
412 $this->assertSame($visibility, $actualVisibility);
421 $path =
'/path/to/your/file';
423 $this->filesystemMock->shouldReceive(
'has')
428 $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
429 $this->expectExceptionMessage(
"Path \"$path\" not found.");
431 $this->subject->getVisibility(
$path);
440 $path =
'/path/to/your/file';
442 $this->filesystemMock->shouldReceive(
'has')
447 $this->filesystemMock->shouldReceive(
'getVisibility')
452 $this->expectException(IOException::class);
453 $this->expectExceptionMessage(
"Could not determine visibility for path '$path'.");
455 $this->subject->getVisibility(
$path);
464 $path =
'/path/to/your/file';
465 $content =
"some awesome content";
467 $this->filesystemMock->shouldReceive(
'write')
469 ->withArgs([
$path, $content])
472 $this->subject->write(
$path, $content);
481 $path =
'/path/to/your/file';
482 $content =
"some awesome content";
484 $this->filesystemMock->shouldReceive(
'write')
486 ->withArgs([
$path, $content])
487 ->andThrow(FileExistsException::class);
489 $this->expectException(FileAlreadyExistsException::class);
490 $this->expectExceptionMessage(
"File \"$path\" already exists.");
492 $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->expectException(IOException::class);
510 $this->expectExceptionMessage(
"Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable.");
512 $this->subject->write(
$path, $content);
521 $path =
'/path/to/your/file';
522 $content =
"some awesome content";
524 $this->filesystemMock->shouldReceive(
'update')
526 ->withArgs([
$path, $content])
529 $this->subject->update(
$path, $content);
538 $path =
'/path/to/your/file';
539 $content =
"some awesome content";
541 $this->filesystemMock->shouldReceive(
'update')
543 ->withArgs([
$path, $content])
546 $this->expectException(IOException::class);
547 $this->expectExceptionMessage(
"Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable.");
549 $this->subject->update(
$path, $content);
558 $path =
'/path/to/your/file';
559 $content =
"some awesome content";
561 $this->filesystemMock->shouldReceive(
'update')
563 ->withArgs([
$path, $content])
564 ->andThrow(FileNotFoundException::class);
566 $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
567 $this->expectExceptionMessage(
"File \"$path\" was not found update failed.");
569 $this->subject->update(
$path, $content);
578 $path =
'/path/to/your/file';
579 $content =
"some awesome content";
581 $this->filesystemMock->shouldReceive(
'put')
583 ->withArgs([
$path, $content])
586 $this->subject->put(
$path, $content);
595 $path =
'/path/to/your/file';
596 $content =
"some awesome content";
598 $this->filesystemMock->shouldReceive(
'put')
600 ->withArgs([
$path, $content])
603 $this->expectException(IOException::class);
604 $this->expectExceptionMessage(
"Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable.");
606 $this->subject->put(
$path, $content);
615 $path =
'/path/to/your/file';
617 $this->filesystemMock->shouldReceive(
'delete')
622 $this->subject->delete(
$path);
631 $path =
'/path/to/your/file';
633 $this->filesystemMock->shouldReceive(
'delete')
638 $this->expectException(IOException::class);
639 $this->expectExceptionMessage(
"Could not delete file \"$path\" because a general IO error occurred. Please check that your target is writable.");
641 $this->subject->delete(
$path);
650 $path =
'/path/to/your/file';
652 $this->filesystemMock->shouldReceive(
'delete')
655 ->andThrow(FileNotFoundException::class);
657 $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
658 $this->expectExceptionMessage(
"File \"$path\" was not found delete operation failed.");
660 $this->subject->delete(
$path);
670 $path =
'/path/to/your/file';
671 $content =
"awesome content";
674 $this->subject = Mockery::mock(FlySystemFileAccess::class, [$this->filesystemMock])->makePartial();
677 ->shouldReceive(
'read')
680 ->andReturn($content)
682 ->shouldReceive(
'delete')
686 $this->subject->readAndDelete(
$path);
696 $destination =
'/dest/path';
698 $this->filesystemMock
699 ->shouldReceive(
'rename')
701 ->withArgs([
$source, $destination])
704 $this->subject->rename(
$source, $destination);
714 $destination =
'/dest/path';
716 $this->filesystemMock
717 ->shouldReceive(
'rename')
719 ->withArgs([
$source, $destination])
720 ->andThrow(FileNotFoundException::class);
722 $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
723 $this->expectExceptionMessage(
"File \"$source\" not found.");
725 $this->subject->rename(
$source, $destination);
735 $destination =
'/dest/path';
737 $this->filesystemMock
738 ->shouldReceive(
'rename')
740 ->withArgs([
$source, $destination])
741 ->andThrow(FileExistsException::class);
743 $this->expectException(FileAlreadyExistsException::class);
744 $this->expectExceptionMessage(
"File \"$destination\" already exists.");
746 $this->subject->rename(
$source, $destination);
756 $destination =
'/dest/path';
758 $this->filesystemMock
759 ->shouldReceive(
'rename')
761 ->withArgs([
$source, $destination])
764 $this->expectException(IOException::class);
765 $this->expectExceptionMessage(
"Could not move file from \"$source\" to \"$destination\".");
767 $this->subject->rename(
$source, $destination);
776 $sourcePath =
'/path/to/your/source/file';
777 $destinationPath =
'/path/to/your/destination/file';
779 $this->filesystemMock->shouldReceive(
'copy')
781 ->withArgs([$sourcePath, $destinationPath])
784 $this->subject->copy($sourcePath, $destinationPath);
793 $sourcePath =
'/path/to/your/source/file';
794 $destinationPath =
'/path/to/your/destination/file';
796 $this->filesystemMock->shouldReceive(
'copy')
798 ->withArgs([$sourcePath, $destinationPath])
801 $this->expectException(IOException::class);
802 $this->expectExceptionMessage(
"Could not copy file \"$sourcePath\" to destination \"$destinationPath\" because a general IO error occurred. Please check that your destination is writable.");
804 $this->subject->copy($sourcePath, $destinationPath);
813 $sourcePath =
'/path/to/your/source/file';
814 $destinationPath =
'/path/to/your/destination/file';
816 $this->filesystemMock->shouldReceive(
'copy')
818 ->withArgs([$sourcePath, $destinationPath])
819 ->andThrow(FileNotFoundException::class);
821 $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
822 $this->expectExceptionMessage(
"File source \"$sourcePath\" was not found copy failed.");
824 $this->subject->copy($sourcePath, $destinationPath);
833 $sourcePath =
'/path/to/your/source/file';
834 $destinationPath =
'/path/to/your/destination/file';
836 $this->filesystemMock->shouldReceive(
'copy')
838 ->withArgs([$sourcePath, $destinationPath])
839 ->andThrow(FileExistsException::class);
841 $this->expectException(FileAlreadyExistsException::class);
842 $this->expectExceptionMessage(
"File destination \"$destinationPath\" already exists copy failed.");
844 $this->subject->copy($sourcePath, $destinationPath);
foreach($mandatory_scripts as $file) $timestamp
This class provides the data size with additional information to remove the work to calculate the siz...
Class FileAlreadyExistsException.
testUpdateWhichShouldSucceed()
@Test @small
testGetVisibilityWithAdapterErrorWhichShouldFail()
@Test @small
testGetMimeTypeWhichShouldSucceed()
@Test @small
testReadWhichShouldSucceed()
@Test @small
testRenameWhichShouldSucceed()
@Test @small
testDeleteWithAdapterErrorWhichShouldFail()
@Test @small
setUp()
Sets up the fixture, for example, open a network connection.
testCopyWhichShouldSucceed()
@Test @small
ILIAS Filesystem Provider FlySystem FlySystemFileAccess $subject
testSetVisibilityThatFailedDueToAdapterFailureWhichShouldFail()
@Test @small
testPutWhichShouldSucceed()
@Test @small
testDeleteWithMissingFileWhichShouldFail()
@Test @small
testUpdateWithMissingFileWhichShouldFail()
@Test @small
testUpdateWithAdapterErrorWhichShouldFail()
@Test @small
testSetVisibilityWithMissingFileWhichShouldFail()
@Test @small
testGetVisibilityWithMissingFileWhichShouldFail()
@Test @small
testWriteWithAdapterErrorWhichShouldFail()
@Test @small
testSetVisibilityWhichShouldSucceed()
@Test @small
testRenameWithExistingDestinationWhichShouldFail()
@Test @small
testCopyWithExistingDestinationFileWhichShouldFail()
@Test @small
testReadWithMissingFileWhichShouldFail()
@Test @small
testGetTimestampWhichShouldSucceed()
@Test @small
testPutWithAdapterErrorWhichShouldFail()
@Test @small
testReadWithGeneralFileAccessErrorWhichShouldFail()
@Test @small
testWriteWithAlreadyExistingFileWhichShouldFail()
@Test @small
testCopyWithAdapterErrorWhichShouldFail()
@Test @small
testGetMimeTypeWithUnknownMimeTypeWhichShouldFail()
@Test @small
testDeleteWhichShouldSucceed()
@Test @small
testWriteWhichShouldSucceed()
@Test @small
testGetVisibilityWhichShouldSucceed()
@Test @small
testCopyWithMissingFileWhichShouldFail()
@Test @small
testReadAndDeleteWhichShouldSucceed()
@Test @small Maybe a useless test.
testGetSizeWithMissingFileWhichShouldFail()
@Test @small
testGetTimestampWithMissingFileWhichShouldFail()
@Test @small
testGetTimestampWithUnknownErrorWhichShouldFail()
@Test @small
testRenameWithMissingSourceWhichShouldFail()
@Test @small
testGetSizeWithUnknownAdapterErrorWhichShouldFail()
@Test @small
testRenameWithGeneralErrorWhichShouldFail()
@Test @small
testGetMimeTypeWithMissingFileWhichShouldFail()
@Test @small
testGetSizeWhichShouldSucceed()
@Test @small
testSetVisibilityWithInvalidAccessModifierWhichShouldFail()
@Test @small
Class FlySystemFileAccess.
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...
Class ChatMainBarProvider \MainMenu\Provider.