27 Util::registerGlobalFunctions();
60 protected function setUp(): void
64 $this->filesystemMock = \Mockery::mock(FilesystemOperator::class);
72 $path =
'/path/to/your/file';
73 $fileContent =
'Awesome file content';
74 $stream = fopen(
'data://text/plain,' . $fileContent, $fileContent,
'r');
76 $this->filesystemMock->shouldReceive(
'readStream')
81 $wrappedStream = $this->subject->readStream(
$path);
83 $this->assertSame($fileContent, $wrappedStream->getContents());
90 $path =
'/path/to/your/file';
92 $this->filesystemMock->shouldReceive(
'readStream')
95 ->andThrow(UnableToReadFile::class);
97 $this->expectException(FileNotFoundException::class);
98 $this->expectExceptionMessage(
"File \"$path\" not found.");
100 $this->subject->readStream(
$path);
107 $path =
'/path/to/your/file';
109 $this->filesystemMock->shouldReceive(
'readStream')
114 $this->expectException(IOException::class);
115 $this->expectExceptionMessage(
"Could not open stream for file \"$path\"");
117 $this->subject->readStream(
$path);
124 $path =
'/path/to/your/file';
125 $fileContent =
'Awesome file content';
128 $this->filesystemMock
129 ->shouldReceive(
'fileExists')
133 ->shouldReceive(
'writeStream')
135 ->withArgs([
$path, \resourceValue()])
138 $this->subject->writeStream(
$path, $stream);
145 $path =
'/path/to/your/file';
146 $fileContent =
'Awesome file content';
150 $this->expectException(\InvalidArgumentException::class);
151 $this->expectExceptionMessage(
'The given stream must not be detached.');
153 $this->subject->writeStream(
$path, $stream);
160 $path =
'/path/to/your/file';
161 $fileContent =
'Awesome file content';
164 $this->filesystemMock
165 ->shouldReceive(
'fileExists')
169 $this->expectException(FileAlreadyExistsException::class);
170 $this->expectExceptionMessage(
"File \"$path\" already exists.");
172 $this->subject->writeStream(
$path, $stream);
179 $path =
'/path/to/your/file';
180 $fileContent =
'Awesome file content';
183 $this->filesystemMock
184 ->shouldReceive(
'fileExists')
188 ->shouldReceive(
'writeStream')
190 ->withArgs([
$path, \resourceValue()])
191 ->andThrow(UnableToWriteFile::class);
193 $this->expectException(IOException::class);
194 $this->expectExceptionMessage(
"Could not write stream to file \"$path\"");
196 $this->subject->writeStream(
$path, $stream);
203 $path =
'/path/to/your/file';
204 $fileContent =
'Awesome file content';
207 $this->filesystemMock->shouldReceive(
'putStream')
209 ->withArgs([
$path, \resourceValue()])
212 $this->subject->putStream(
$path, $stream);
219 $path =
'/path/to/your/file';
220 $fileContent =
'Awesome file content';
223 $this->filesystemMock->shouldReceive(
'putStream')
225 ->withArgs([
$path, \resourceValue()])
228 $this->expectException(IOException::class);
229 $this->expectExceptionMessage(
"Could not put stream content into \"$path\"");
231 $this->subject->putStream(
$path, $stream);
238 $path =
'/path/to/your/file';
239 $fileContent =
'Awesome file content';
243 $this->expectException(\InvalidArgumentException::class);
244 $this->expectExceptionMessage(
'The given stream must not be detached.');
246 $this->subject->putStream(
$path, $stream);
253 $path =
'/path/to/your/file';
254 $fileContent =
'Awesome file content';
257 $this->filesystemMock->shouldReceive(
'writeStream')
259 ->withArgs([
$path, \resourceValue()])
262 $this->subject->updateStream(
$path, $stream);
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.');
277 $this->subject->updateStream(
$path, $stream);
284 $path =
'/path/to/your/file';
285 $fileContent =
'Awesome file content';
288 $this->filesystemMock
289 ->shouldReceive(
'writeStream')
291 ->withArgs([
$path, \resourceValue()])
292 ->andThrow(UnableToWriteFile::class);
294 $this->expectException(IOException::class);
295 $this->expectExceptionMessage(
"Unable to update Stream in \"$path\".");
297 $this->subject->updateStream(
$path, $stream);
304 $path =
'/path/to/your/file';
305 $fileContent =
'Awesome file content';
308 $this->filesystemMock
309 ->shouldReceive(
'writeStream')
311 ->withArgs([
$path, \resourceValue()])
312 ->andThrow(UnableToWriteFile::class);
314 $this->expectException(FileNotFoundException::class);
315 $this->expectExceptionMessage(
"Unable to update Stream in \"$path\".");
317 $this->subject->updateStream(
$path, $stream);
testWriteStreamWithExistingFileWhichShouldFail()
testWriteStreamWhichShouldSucceed()
testPutStreamWithDetachedStreamWhichShouldFail()
testPutStreamWhichShouldSucceed()
testWriteStreamWithDetachedStreamWhichShouldFail()
testReadStreamWhichShouldSucceed()
FlySystemFileStreamAccess $subject
testUpdateStreamWithDetachedStreamWhichShouldFail()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testWriteStreamWithFailingAdapterWhichShouldFail()
testUpdateStreamWithGeneralFailureWhichShouldFail()
testUpdateStreamWithMissingFileWhichShouldFail()
testReadStreamWithMissingFileWhichShouldFail()
testUpdateStreamWhichShouldSucceed()
LegacyMockInterface $filesystemMock
static ofString(string $string)
Creates a new stream with an initial value.
setUp()
Sets up the fixture, for example, open a network connection.
testPutStreamWithGeneralFailureWhichShouldFail()
testReadStreamWithGeneralFailureWhichShouldFail()