File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 99use Gt \Http \Uri ;
1010use Gt \Input \Input ;
1111use Gt \Input \InputData \Datum \FileUpload ;
12+ use Gt \Input \InputData \Datum \InputDatum ;
1213use Gt \Input \InputData \FileUploadInputData ;
1314use PHPUnit \Framework \MockObject \MockObject ;
1415use PHPUnit \Framework \TestCase ;
@@ -151,6 +152,28 @@ public function testWithUploadedFilesFullToEmpty() {
151152 self ::assertEmpty ($ sutEmpty ->getUploadedFiles ());
152153 }
153154
155+ public function testWithUploadedFilesEmptyToFull () {
156+ $ sutEmpty = self ::getServerRequest (
157+ "post " ,
158+ "/example " ,
159+ [],
160+ [],
161+ [
162+ "files " => [],
163+ ]
164+ );
165+ self ::assertEmpty ($ sutEmpty ->getUploadedFiles ());
166+
167+ $ file1 = self ::createMock (FileUpload::class);
168+ $ file2 = self ::createMock (FileUpload::class);
169+
170+ $ sutFull = $ sutEmpty ->withUploadedFiles ([
171+ $ file1 ,
172+ $ file2 ,
173+ ]);
174+ self ::assertCount (2 , $ sutFull ->getUploadedFiles ());
175+ }
176+
154177 protected function getServerRequest (
155178 string $ method = null ,
156179 string $ uri = null ,
@@ -245,6 +268,15 @@ protected function getMockInput(
245268 $ mock ->method ("getAll " )
246269 ->with (Input::DATA_FILES )
247270 ->willReturn ($ fileUploadParameters );
271+ $ mock ->method ("add " )
272+ ->willReturnCallback (function (string $ key , InputDatum $ datum , string $ method )use (&$ fileArray ) {
273+ if ($ method === Input::DATA_FILES ) {
274+ /** @var FileUpload $datum */
275+ $ fileArray [$ key ] = [
276+ "name " => $ datum ->getClientFilename ()
277+ ];
278+ }
279+ });
248280 return $ mock ;
249281 }
250282
You can’t perform that action at this time.
0 commit comments