5require_once(
'./libs/composer/vendor/autoload.php');
15use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
16use Mockery\MockInterface;
17use PHPUnit\Framework\TestCase;
18use Psr\Http\Message\UploadedFileInterface;
32 use MockeryPHPUnitIntegration;
58 $processorMock = \Mockery::mock(PreProcessor::class);
59 $this->prePorcessorManagerMock->shouldReceive(
'with')
61 ->with($processorMock);
63 $this->subject->register($processorMock);
72 $processorMock = \Mockery::mock(PreProcessor::class);
74 $this->globalHttpStateMock->shouldReceive(
'request->getUploadedFiles')
78 $this->expectException(IllegalStateException::class);
79 $this->expectExceptionMessage(
'Can not register processor after the upload was processed.');
81 $this->subject->process();
82 $this->subject->register($processorMock);
94 ->shouldReceive(
'getClientFilename')
96 ->andReturn(
'hello.txt')
98 ->shouldReceive(
'getSize')
102 ->shouldReceive(
'getClientMediaType')
104 ->andReturn(
'text/plain')
106 ->shouldReceive(
'getError')
108 ->andReturn(UPLOAD_ERR_OK)
110 ->shouldReceive(
'getStream')
118 $this->prePorcessorManagerMock->shouldReceive(
'process')
121 ->andReturn($processingResult);
123 $this->globalHttpStateMock->shouldReceive(
'request->getUploadedFiles')
125 ->andReturn($uploadedFiles);
127 $this->subject->process();
138 ->shouldReceive(
'getClientFilename')
140 ->andReturn(
'hello.txt')
142 ->shouldReceive(
'getSize')
146 ->shouldReceive(
'getClientMediaType')
148 ->andReturn(
'text/plain')
150 ->shouldReceive(
'getError')
152 ->andReturn(UPLOAD_ERR_PARTIAL)
154 ->shouldReceive(
'getStream')
162 $this->globalHttpStateMock->shouldReceive(
'request->getUploadedFiles')
164 ->andReturn($uploadedFiles);
166 $this->subject->process();
168 $result = $this->subject->getResults()[0];
180 $this->globalHttpStateMock->shouldReceive(
'request->getUploadedFiles')
183 $this->assertFalse($this->subject->hasUploads());
194 $this->globalHttpStateMock->shouldReceive(
'request->getUploadedFiles')
198 $this->assertTrue($this->subject->hasUploads());
208 for (
$i = 0;
$i < 10;
$i++) {
209 $files[] = Mockery::mock(UploadedFileInterface::class);
212 $this->globalHttpStateMock->shouldReceive(
'request->getUploadedFiles')
216 $this->assertTrue($this->subject->hasUploads());
227 $this->prePorcessorManagerMock = \Mockery::mock(PreProcessorManager::class);
228 $this->filesystemsMock = \Mockery::mock(Filesystems::class);
229 $this->globalHttpStateMock = \Mockery::mock(GlobalHttpState::class);
231 $this->subject =
new FileUploadImpl($this->prePorcessorManagerMock, $this->filesystemsMock, $this->globalHttpStateMock);
An exception for terminatinating execution or to throw for unit testing.
const REJECTED
Upload got rejected by a processor.
Class IllegalStateException.
Class FileUploadImplTest.
testRegisterWithProcessedFilesWhichShouldFail()
@Test @small
testProcessWithFailedUploadWhichShouldGetRejected()
@Test @small
testRegisterWhichShouldSucceed()
@Test @small
testHasUploadsWithoutUploadedFiles()
testProcessWhichShouldSucceed()
@Test @small
testHasUploadsWithMultipleUploadedFile()
testHasUploadsWithSingleUploadedFile()
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 PreProcessorManager.
Class Filesystems The Filesystems interface defines the access methods which can be used to fetch the...
Interface GlobalHttpState.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...