21use PHPUnit\Framework\Attributes\BackupGlobals;
22use PHPUnit\Framework\Attributes\BackupStaticProperties;
23use PHPUnit\Framework\Attributes\PreserveGlobalState;
24use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
25use PHPUnit\Framework\Attributes\Test;
26use PHPUnit\Framework\Attributes\Small;
28require_once(
'./vendor/composer/vendor/autoload.php');
38use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
39use Mockery\MockInterface;
40use PHPUnit\Framework\TestCase;
41use Psr\Http\Message\UploadedFileInterface;
48#[BackupGlobals(false)]
49#[BackupStaticProperties(false)]
50#[PreserveGlobalState(false)]
51#[RunTestsInSeparateProcesses]
54 use MockeryPHPUnitIntegration;
74 $processorMock = \Mockery::mock(PreProcessor::class);
75 $this->prePorcessorManagerMock->shouldReceive(
'with')
77 ->with($processorMock);
79 $this->subject->register($processorMock);
86 $processorMock = \Mockery::mock(PreProcessor::class);
88 $this->globalHttpStateMock->shouldReceive(
'request->getUploadedFiles')
92 $this->expectException(IllegalStateException::class);
93 $this->expectExceptionMessage(
'Can not register processor after the upload was processed.');
95 $this->subject->process();
96 $this->subject->register($processorMock);
104 $uploadedFile = Mockery::mock(UploadedFileInterface::class);
106 ->shouldReceive(
'getClientFilename')
108 ->andReturn(
'hello.txt')
110 ->shouldReceive(
'getSize')
114 ->shouldReceive(
'getClientMediaType')
116 ->andReturn(
'text/plain')
118 ->shouldReceive(
'getError')
120 ->andReturn(UPLOAD_ERR_OK)
122 ->shouldReceive(
'getStream')
130 $this->prePorcessorManagerMock->shouldReceive(
'process')
133 ->andReturn($processingResult);
135 $this->globalHttpStateMock->shouldReceive(
'request->getUploadedFiles')
137 ->andReturn($uploadedFiles);
139 $this->subject->process();
146 $uploadedFile = Mockery::mock(UploadedFileInterface::class);
148 ->shouldReceive(
'getClientFilename')
150 ->andReturn(
'hello.txt')
152 ->shouldReceive(
'getSize')
156 ->shouldReceive(
'getClientMediaType')
158 ->andReturn(
'text/plain')
160 ->shouldReceive(
'getError')
162 ->andReturn(UPLOAD_ERR_PARTIAL)
164 ->shouldReceive(
'getStream')
172 $this->globalHttpStateMock->shouldReceive(
'request->getUploadedFiles')
174 ->andReturn($uploadedFiles);
176 $this->subject->process();
178 $result = $this->subject->getResults()[0];
188 $this->globalHttpStateMock->shouldReceive(
'request->getUploadedFiles')
191 $this->assertFalse($this->subject->hasUploads());
198 $uploadedFile = Mockery::mock(UploadedFileInterface::class);
200 $this->globalHttpStateMock->shouldReceive(
'request->getUploadedFiles')
202 ->andReturn([ $uploadedFile ]);
204 $this->assertTrue($this->subject->hasUploads());
212 for ($i = 0; $i < 10; $i++) {
213 $files[] = Mockery::mock(UploadedFileInterface::class);
216 $this->globalHttpStateMock->shouldReceive(
'request->getUploadedFiles')
220 $this->assertTrue($this->subject->hasUploads());
231 $this->prePorcessorManagerMock = \Mockery::mock(PreProcessorManager::class);
232 $filesystemsMock = \Mockery::mock(Filesystems::class);
233 $this->globalHttpStateMock = \Mockery::mock(GlobalHttpState::class);
235 $this->subject =
new FileUploadImpl($this->prePorcessorManagerMock, $filesystemsMock, $this->globalHttpStateMock);
Class IllegalStateException.
Class FileUploadImplTest.
testRegisterWithProcessedFilesWhichShouldFail()
testProcessWithFailedUploadWhichShouldGetRejected()
testRegisterWhichShouldSucceed()
testHasUploadsWithoutUploadedFiles()
testProcessWhichShouldSucceed()
testHasUploadsWithMultipleUploadedFile()
testHasUploadsWithSingleUploadedFile()
Stream factory which enables the user to create streams without the knowledge of the concrete class.
static ofString(string $string)
Creates a new stream with an initial value.
Class PreProcessorManager.
The Filesystems interface defines the access methods which can be used to fetch the different filesys...
Interface GlobalHttpState.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...