5require_once(
'./libs/composer/vendor/autoload.php');
 
   15use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
 
   16use Mockery\MockInterface;
 
   17use PHPUnit\Framework\TestCase;
 
   31    use MockeryPHPUnitIntegration;
 
   50        date_default_timezone_set(
'Africa/Lagos');
 
   51        $this->filesystemMock = Mockery::mock(FilesystemInterface::class);
 
   62        $fileContent = 
'Test file content.';
 
   63        $this->filesystemMock->shouldReceive(
'read')
 
   65            ->andReturn($fileContent);
 
   67        $actualContent = $this->subject->read(
'/path/to/your/file');
 
   68        $this->assertSame($fileContent, $actualContent);
 
   77        $path = 
'/path/to/your/file';
 
   78        $this->filesystemMock->shouldReceive(
'read')
 
   83        $this->expectException(IOException::class);
 
   84        $this->expectExceptionMessage(
"Could not access the file \"$path\".");
 
   86        $this->subject->read(
$path);
 
   95        $path = 
'/path/to/your/file';
 
   96        $this->filesystemMock->shouldReceive(
'read')
 
   99            ->andThrow(FileNotFoundException::class);
 
  101        $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
 
  102        $this->expectExceptionMessage(
"File \"$path\" not found.");
 
  104        $this->subject->read(
$path);
 
  113        $mimeType = 
'image/jpeg';
 
  114        $this->filesystemMock->shouldReceive(
'getMimetype')
 
  116            ->andReturn($mimeType);
 
  118        $actualMimeType = $this->subject->getMimeType(
'/path/to/your/file');
 
  119        $this->assertSame($mimeType, $actualMimeType);
 
  128        $path = 
'/path/to/your/file';
 
  129        $this->filesystemMock->shouldReceive(
'getMimetype')
 
  134        $this->expectException(IOException::class);
 
  135        $this->expectExceptionMessage(
"Could not determine the MIME type of the file \"$path\".");
 
  137        $this->subject->getMimeType(
$path);
 
  146        $path = 
'/path/to/your/file';
 
  147        $this->filesystemMock->shouldReceive(
'getMimetype')
 
  150            ->andThrow(FileNotFoundException::class);
 
  152        $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
 
  153        $this->expectExceptionMessage(
"File \"$path\" not found.");
 
  155        $this->subject->getMimeType(
$path);
 
  165        $this->filesystemMock->shouldReceive(
'getTimestamp')
 
  169        $actualTimestamp = $this->subject->getTimestamp(
'/path/to/your/file');
 
  182        $this->assertEquals(
new \DateTime(
$timestamp), $actualTimestamp);
 
  191        $path = 
'/path/to/your/file';
 
  192        $this->filesystemMock->shouldReceive(
'getTimestamp')
 
  197        $this->expectException(IOException::class);
 
  198        $this->expectExceptionMessage(
"Could not lookup timestamp of the file \"$path\".");
 
  200        $this->subject->getTimestamp(
$path);
 
  209        $path = 
'/path/to/your/file';
 
  210        $this->filesystemMock->shouldReceive(
'getTimestamp')
 
  213            ->andThrow(FileNotFoundException::class);
 
  215        $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
 
  216        $this->expectExceptionMessage(
"File \"$path\" not found.");
 
  218        $this->subject->getTimestamp(
$path);
 
  231        $this->filesystemMock->shouldReceive(
'getSize')
 
  233            ->andReturn($rawSize);
 
  235        $actualSize = $this->subject->getSize(
'/path/to/your/file', 
DataSize::KiB);
 
  236        $this->assertSame(
$size->getSize(), $actualSize->getSize(), 
'', $delta);
 
  245        $path = 
'/path/to/your/file';
 
  246        $this->filesystemMock->shouldReceive(
'getSize')
 
  251        $this->expectException(IOException::class);
 
  252        $this->expectExceptionMessage(
"Could not calculate the file size of the file \"$path\".");
 
  263        $path = 
'/path/to/your/file';
 
  264        $this->filesystemMock->shouldReceive(
'getSize')
 
  267            ->andThrow(FileNotFoundException::class);
 
  269        $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
 
  270        $this->expectExceptionMessage(
"File \"$path\" not found.");
 
  281        $path = 
'/path/to/your/file';
 
  282        $visibility = 
"private";
 
  284        $this->filesystemMock->shouldReceive(
'has')
 
  289        $this->filesystemMock->shouldReceive(
'setVisibility')
 
  291            ->withArgs([
$path, $visibility])
 
  294        $operationSuccessful = $this->subject->setVisibility(
$path, $visibility);
 
  295        $this->assertTrue($operationSuccessful);
 
  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->assertFalse($operationSuccessful);
 
  327        $path = 
'/path/to/your/file';
 
  328        $visibility = 
"private";
 
  330        $this->filesystemMock->shouldReceive(
'has')
 
  335        $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
 
  336        $this->expectExceptionMessage(
"Path \"$path\" not found.");
 
  338        $this->subject->setVisibility(
$path, $visibility);
 
  347        $path = 
'/path/to/your/file';
 
  348        $visibility = 
"not valid";
 
  350        $this->filesystemMock->shouldReceive(
'has')
 
  355        $this->expectException(\InvalidArgumentException::class);
 
  356        $this->expectExceptionMessage(
"The access must be 'public' or 'private' but '$visibility' was given.");
 
  358        $this->subject->setVisibility(
$path, $visibility);
 
  367        $path = 
'/path/to/your/file';
 
  368        $visibility = 
"private";
 
  370        $this->filesystemMock->shouldReceive(
'has')
 
  375        $this->filesystemMock->shouldReceive(
'getVisibility')
 
  378            ->andReturn($visibility);
 
  380        $actualVisibility = $this->subject->getVisibility(
$path);
 
  381        $this->assertSame($visibility, $actualVisibility);
 
  390        $path = 
'/path/to/your/file';
 
  392        $this->filesystemMock->shouldReceive(
'has')
 
  397        $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
 
  398        $this->expectExceptionMessage(
"Path \"$path\" not found.");
 
  400        $this->subject->getVisibility(
$path);
 
  409        $path = 
'/path/to/your/file';
 
  411        $this->filesystemMock->shouldReceive(
'has')
 
  416        $this->filesystemMock->shouldReceive(
'getVisibility')
 
  421        $this->expectException(IOException::class);
 
  422        $this->expectExceptionMessage(
"Could not determine visibility for path '$path'.");
 
  424        $this->subject->getVisibility(
$path);
 
  433        $path = 
'/path/to/your/file';
 
  434        $content = 
"some awesome content";
 
  436        $this->filesystemMock->shouldReceive(
'write')
 
  438            ->withArgs([
$path, $content])
 
  441        $this->subject->write(
$path, $content);
 
  450        $path = 
'/path/to/your/file';
 
  451        $content = 
"some awesome content";
 
  453        $this->filesystemMock->shouldReceive(
'write')
 
  455            ->withArgs([
$path, $content])
 
  456            ->andThrow(FileExistsException::class);
 
  458        $this->expectException(FileAlreadyExistsException::class);
 
  459        $this->expectExceptionMessage(
"File \"$path\" already exists.");
 
  461        $this->subject->write(
$path, $content);
 
  470        $path = 
'/path/to/your/file';
 
  471        $content = 
"some awesome content";
 
  473        $this->filesystemMock->shouldReceive(
'write')
 
  475            ->withArgs([
$path, $content])
 
  478        $this->expectException(IOException::class);
 
  479        $this->expectExceptionMessage(
"Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable.");
 
  481        $this->subject->write(
$path, $content);
 
  490        $path = 
'/path/to/your/file';
 
  491        $content = 
"some awesome content";
 
  493        $this->filesystemMock->shouldReceive(
'update')
 
  495            ->withArgs([
$path, $content])
 
  498        $this->subject->update(
$path, $content);
 
  507        $path = 
'/path/to/your/file';
 
  508        $content = 
"some awesome content";
 
  510        $this->filesystemMock->shouldReceive(
'update')
 
  512            ->withArgs([
$path, $content])
 
  515        $this->expectException(IOException::class);
 
  516        $this->expectExceptionMessage(
"Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable.");
 
  518        $this->subject->update(
$path, $content);
 
  527        $path = 
'/path/to/your/file';
 
  528        $content = 
"some awesome content";
 
  530        $this->filesystemMock->shouldReceive(
'update')
 
  532            ->withArgs([
$path, $content])
 
  533            ->andThrow(FileNotFoundException::class);
 
  535        $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
 
  536        $this->expectExceptionMessage(
"File \"$path\" was not found update failed.");
 
  538        $this->subject->update(
$path, $content);
 
  547        $path = 
'/path/to/your/file';
 
  548        $content = 
"some awesome content";
 
  550        $this->filesystemMock->shouldReceive(
'put')
 
  552            ->withArgs([
$path, $content])
 
  555        $this->subject->put(
$path, $content);
 
  564        $path = 
'/path/to/your/file';
 
  565        $content = 
"some awesome content";
 
  567        $this->filesystemMock->shouldReceive(
'put')
 
  569            ->withArgs([
$path, $content])
 
  572        $this->expectException(IOException::class);
 
  573        $this->expectExceptionMessage(
"Could not write to file \"$path\" because a general IO error occurred. Please check that your destination is writable.");
 
  575        $this->subject->put(
$path, $content);
 
  584        $path = 
'/path/to/your/file';
 
  586        $this->filesystemMock->shouldReceive(
'delete')
 
  591        $this->subject->delete(
$path);
 
  600        $path = 
'/path/to/your/file';
 
  602        $this->filesystemMock->shouldReceive(
'delete')
 
  607        $this->expectException(IOException::class);
 
  608        $this->expectExceptionMessage(
"Could not delete file \"$path\" because a general IO error occurred. Please check that your target is writable.");
 
  610        $this->subject->delete(
$path);
 
  619        $path = 
'/path/to/your/file';
 
  621        $this->filesystemMock->shouldReceive(
'delete')
 
  624            ->andThrow(FileNotFoundException::class);
 
  626        $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
 
  627        $this->expectExceptionMessage(
"File \"$path\" was not found delete operation failed.");
 
  629        $this->subject->delete(
$path);
 
  640        $path = 
'/path/to/your/file';
 
  641        $content = 
"awesome content";
 
  644        $this->subject = Mockery::mock(FlySystemFileAccess::class, [$this->filesystemMock])->makePartial();
 
  647            ->shouldReceive(
'read')
 
  650                ->andReturn($content)
 
  652            ->shouldReceive(
'delete')
 
  656        $this->subject->readAndDelete(
$path);
 
  669        $this->filesystemMock
 
  670            ->shouldReceive(
'rename')
 
  687        $this->filesystemMock
 
  688            ->shouldReceive(
'rename')
 
  691            ->andThrow(FileNotFoundException::class);
 
  693        $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
 
  694        $this->expectExceptionMessage(
"File \"$source\" not found.");
 
  708        $this->filesystemMock
 
  709            ->shouldReceive(
'rename')
 
  712            ->andThrow(FileExistsException::class);
 
  714        $this->expectException(FileAlreadyExistsException::class);
 
  715        $this->expectExceptionMessage(
"File \"$destination\" already exists.");
 
  729        $this->filesystemMock
 
  730            ->shouldReceive(
'rename')
 
  735        $this->expectException(IOException::class);
 
  736        $this->expectExceptionMessage(
"Could not move file from \"$source\" to \"$destination\".");
 
  747        $sourcePath = 
'/path/to/your/source/file';
 
  748        $destinationPath = 
'/path/to/your/destination/file';
 
  750        $this->filesystemMock->shouldReceive(
'copy')
 
  752            ->withArgs([$sourcePath, $destinationPath])
 
  755        $this->subject->copy($sourcePath, $destinationPath);
 
  764        $sourcePath = 
'/path/to/your/source/file';
 
  765        $destinationPath = 
'/path/to/your/destination/file';
 
  767        $this->filesystemMock->shouldReceive(
'copy')
 
  769            ->withArgs([$sourcePath, $destinationPath])
 
  772        $this->expectException(IOException::class);
 
  773        $this->expectExceptionMessage(
"Could not copy file \"$sourcePath\" to destination \"$destinationPath\" because a general IO error occurred. Please check that your destination is writable.");
 
  775        $this->subject->copy($sourcePath, $destinationPath);
 
  784        $sourcePath = 
'/path/to/your/source/file';
 
  785        $destinationPath = 
'/path/to/your/destination/file';
 
  787        $this->filesystemMock->shouldReceive(
'copy')
 
  789            ->withArgs([$sourcePath, $destinationPath])
 
  790            ->andThrow(FileNotFoundException::class);
 
  792        $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
 
  793        $this->expectExceptionMessage(
"File source \"$sourcePath\" was not found copy failed.");
 
  795        $this->subject->copy($sourcePath, $destinationPath);
 
  804        $sourcePath = 
'/path/to/your/source/file';
 
  805        $destinationPath = 
'/path/to/your/destination/file';
 
  807        $this->filesystemMock->shouldReceive(
'copy')
 
  809            ->withArgs([$sourcePath, $destinationPath])
 
  810            ->andThrow(FileExistsException::class);
 
  812        $this->expectException(FileAlreadyExistsException::class);
 
  813        $this->expectExceptionMessage(
"File destination \"$destinationPath\" already exists copy failed.");
 
  815        $this->subject->copy($sourcePath, $destinationPath);
 
foreach($mandatory_scripts as $file) $timestamp
An exception for terminatinating execution or to throw for unit testing.
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
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
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.
@method array getWithMetadata(string $path, array $metadata) @method bool forceCopy(string $path,...
Class FlySystemFileAccessTest.