5require_once(
'./libs/composer/vendor/autoload.php');
14use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
15use Mockery\MockInterface;
16use PHPUnit\Framework\TestCase;
30 use MockeryPHPUnitIntegration;
50 $this->filesystemMock = \Mockery::mock(FilesystemInterface::class);
60 $path =
'/path/to/your/file';
61 $fileContent =
'Awesome file content';
62 $stream = fopen(
'data://text/plain,' . $fileContent, $fileContent,
'r');
64 $this->filesystemMock->shouldReceive(
'readStream')
69 $wrappedStream = $this->subject->readStream(
$path);
71 $this->assertSame($fileContent, $wrappedStream->getContents());
80 $path =
'/path/to/your/file';
82 $this->filesystemMock->shouldReceive(
'readStream')
85 ->andThrow(FileNotFoundException::class);
87 $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
88 $this->expectExceptionMessage(
"File \"$path\" not found.");
90 $this->subject->readStream(
$path);
99 $path =
'/path/to/your/file';
101 $this->filesystemMock->shouldReceive(
'readStream')
106 $this->expectException(IOException::class);
107 $this->expectExceptionMessage(
"Could not open stream for file \"$path\"");
109 $this->subject->readStream(
$path);
118 $path =
'/path/to/your/file';
119 $fileContent =
'Awesome file content';
122 $this->filesystemMock->shouldReceive(
'writeStream')
124 ->withArgs([
$path, resourceValue()])
136 $path =
'/path/to/your/file';
137 $fileContent =
'Awesome file content';
141 $this->expectException(\InvalidArgumentException::class);
142 $this->expectExceptionMessage(
'The given stream must not be detached.');
153 $path =
'/path/to/your/file';
154 $fileContent =
'Awesome file content';
157 $this->filesystemMock->shouldReceive(
'writeStream')
159 ->withArgs([
$path, resourceValue()])
160 ->andThrow(FileExistsException::class);
162 $this->expectException(FileAlreadyExistsException::class);
163 $this->expectExceptionMessage(
"File \"$path\" already exists.");
174 $path =
'/path/to/your/file';
175 $fileContent =
'Awesome file content';
178 $this->filesystemMock->shouldReceive(
'writeStream')
180 ->withArgs([
$path, resourceValue()])
183 $this->expectException(IOException::class);
184 $this->expectExceptionMessage(
"Could not write stream to file \"$path\"");
195 $path =
'/path/to/your/file';
196 $fileContent =
'Awesome file content';
199 $this->filesystemMock->shouldReceive(
'putStream')
201 ->withArgs([
$path, resourceValue()])
213 $path =
'/path/to/your/file';
214 $fileContent =
'Awesome file content';
217 $this->filesystemMock->shouldReceive(
'putStream')
219 ->withArgs([
$path, resourceValue()])
222 $this->expectException(IOException::class);
223 $this->expectExceptionMessage(
"Could not put stream content into \"$path\"");
234 $path =
'/path/to/your/file';
235 $fileContent =
'Awesome file content';
239 $this->expectException(\InvalidArgumentException::class);
240 $this->expectExceptionMessage(
'The given stream must not be detached.');
251 $path =
'/path/to/your/file';
252 $fileContent =
'Awesome file content';
255 $this->filesystemMock->shouldReceive(
'updateStream')
257 ->withArgs([
$path, resourceValue()])
269 $path =
'/path/to/your/file';
270 $fileContent =
'Awesome file content';
274 $this->expectException(\InvalidArgumentException::class);
275 $this->expectExceptionMessage(
'The given stream must not be detached.');
286 $path =
'/path/to/your/file';
287 $fileContent =
'Awesome file content';
290 $this->filesystemMock->shouldReceive(
'updateStream')
292 ->withArgs([
$path, resourceValue()])
295 $this->expectException(IOException::class);
296 $this->expectExceptionMessage(
"Could not update file \"$path\"");
307 $path =
'/path/to/your/file';
308 $fileContent =
'Awesome file content';
311 $this->filesystemMock->shouldReceive(
'updateStream')
313 ->withArgs([
$path, resourceValue()])
314 ->andThrow(FileNotFoundException::class);
316 $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
317 $this->expectExceptionMessage(
"File \"$path\" not found.");
An exception for terminatinating execution or to throw for unit testing.
Class FlySystemFileStreamAccessTest.
testWriteStreamWithExistingFileWhichShouldFail()
@Test @small
testPutStreamWithDetachedStreamWhichShouldFail()
@Test @small
testUpdateStreamWithMissingFileWhichShouldFail()
@Test @small
testPutStreamWithGeneralFailureWhichShouldFail()
@Test @small
testUpdateStreamWithGeneralFailureWhichShouldFail()
@Test @small
testUpdateStreamWithDetachedStreamWhichShouldFail()
@Test @small
testPutStreamWhichShouldSucceed()
@Test @small
setUp()
Sets up the fixture, for example, open a network connection.
testWriteStreamWithFailingAdapterWhichShouldFail()
@Test @small
testReadStreamWhichShouldSucceed()
@Test @small
testUpdateStreamWhichShouldSucceed()
@Test @small
testWriteStreamWhichShouldSucceed()
@Test @small
testReadStreamWithGeneralFailureWhichShouldFail()
@Test @small
testReadStreamWithMissingFileWhichShouldFail()
@Test @small
testWriteStreamWithDetachedStreamWhichShouldFail()
@Test @small
Class FileAlreadyExistsException.
Class FlySystemFileStreamAccess.
static ofString($string)
Creates a new stream with an initial value.
Class FlySystemFileAccessTest.
$stream
PHP stream implementation.