5require_once(
'./libs/composer/vendor/autoload.php');
6\Hamcrest\Util::registerGlobalFunctions();
12use League\Flysystem\FileExistsException;
13use League\Flysystem\FileNotFoundException;
14use League\Flysystem\FilesystemInterface;
15use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
16use Mockery\MockInterface;
17use PHPUnit\Framework\TestCase;
31 use MockeryPHPUnitIntegration;
47 protected function setUp() : void
51 $this->filesystemMock = \Mockery::mock(FilesystemInterface::class);
61 $path =
'/path/to/your/file';
62 $fileContent =
'Awesome file content';
63 $stream = fopen(
'data://text/plain,' . $fileContent, $fileContent,
'r');
65 $this->filesystemMock->shouldReceive(
'readStream')
70 $wrappedStream = $this->subject->readStream($path);
72 $this->assertSame($fileContent, $wrappedStream->getContents());
81 $path =
'/path/to/your/file';
83 $this->filesystemMock->shouldReceive(
'readStream')
86 ->andThrow(FileNotFoundException::class);
88 $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
89 $this->expectExceptionMessage(
"File \"$path\" not found.");
91 $this->subject->readStream($path);
100 $path =
'/path/to/your/file';
102 $this->filesystemMock->shouldReceive(
'readStream')
107 $this->expectException(IOException::class);
108 $this->expectExceptionMessage(
"Could not open stream for file \"$path\"");
110 $this->subject->readStream($path);
119 $path =
'/path/to/your/file';
120 $fileContent =
'Awesome file content';
123 $this->filesystemMock->shouldReceive(
'writeStream')
125 ->withArgs([$path, \resourceValue()])
128 $this->subject->writeStream($path, $stream);
137 $path =
'/path/to/your/file';
138 $fileContent =
'Awesome file content';
142 $this->expectException(\InvalidArgumentException::class);
143 $this->expectExceptionMessage(
'The given stream must not be detached.');
145 $this->subject->writeStream($path, $stream);
154 $path =
'/path/to/your/file';
155 $fileContent =
'Awesome file content';
158 $this->filesystemMock->shouldReceive(
'writeStream')
160 ->withArgs([$path, \resourceValue()])
161 ->andThrow(FileExistsException::class);
163 $this->expectException(FileAlreadyExistsException::class);
164 $this->expectExceptionMessage(
"File \"$path\" already exists.");
166 $this->subject->writeStream($path, $stream);
175 $path =
'/path/to/your/file';
176 $fileContent =
'Awesome file content';
179 $this->filesystemMock->shouldReceive(
'writeStream')
181 ->withArgs([$path, \resourceValue()])
184 $this->expectException(IOException::class);
185 $this->expectExceptionMessage(
"Could not write stream to file \"$path\"");
187 $this->subject->writeStream($path, $stream);
196 $path =
'/path/to/your/file';
197 $fileContent =
'Awesome file content';
200 $this->filesystemMock->shouldReceive(
'putStream')
202 ->withArgs([$path, \resourceValue()])
205 $this->subject->putStream($path, $stream);
214 $path =
'/path/to/your/file';
215 $fileContent =
'Awesome file content';
218 $this->filesystemMock->shouldReceive(
'putStream')
220 ->withArgs([$path, \resourceValue()])
223 $this->expectException(IOException::class);
224 $this->expectExceptionMessage(
"Could not put stream content into \"$path\"");
226 $this->subject->putStream($path, $stream);
235 $path =
'/path/to/your/file';
236 $fileContent =
'Awesome file content';
240 $this->expectException(\InvalidArgumentException::class);
241 $this->expectExceptionMessage(
'The given stream must not be detached.');
243 $this->subject->putStream($path, $stream);
252 $path =
'/path/to/your/file';
253 $fileContent =
'Awesome file content';
256 $this->filesystemMock->shouldReceive(
'updateStream')
258 ->withArgs([$path, \resourceValue()])
261 $this->subject->updateStream($path, $stream);
270 $path =
'/path/to/your/file';
271 $fileContent =
'Awesome file content';
275 $this->expectException(\InvalidArgumentException::class);
276 $this->expectExceptionMessage(
'The given stream must not be detached.');
278 $this->subject->updateStream($path, $stream);
287 $path =
'/path/to/your/file';
288 $fileContent =
'Awesome file content';
291 $this->filesystemMock->shouldReceive(
'updateStream')
293 ->withArgs([$path, \resourceValue()])
296 $this->expectException(IOException::class);
297 $this->expectExceptionMessage(
"Could not update file \"$path\"");
299 $this->subject->updateStream($path, $stream);
308 $path =
'/path/to/your/file';
309 $fileContent =
'Awesome file content';
312 $this->filesystemMock->shouldReceive(
'updateStream')
314 ->withArgs([$path, \resourceValue()])
315 ->andThrow(FileNotFoundException::class);
317 $this->expectException(\
ILIAS\
Filesystem\Exception\FileNotFoundException::class);
318 $this->expectExceptionMessage(
"File \"$path\" not found.");
320 $this->subject->updateStream($path, $stream);
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 IOException Indicates general problems with the input or output operations.
Class FlySystemFileStreamAccess Streaming access implementation of the fly system library.
Class Streams Stream factory which enables the user to create streams without the knowledge of the co...
static ofString($string)
Creates a new stream with an initial value.
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...
Class ChatMainBarProvider \MainMenu\Provider.