Skip to content

Commit

Permalink
Testing withUploadedFiles is immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Jan 27, 2019
1 parent b313273 commit b886e94
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/unit/ServerRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Gt\Http\Uri;
use Gt\Input\Input;
use Gt\Input\InputData\Datum\FileUpload;
use Gt\Input\InputData\Datum\InputDatum;
use Gt\Input\InputData\FileUploadInputData;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -151,6 +152,28 @@ public function testWithUploadedFilesFullToEmpty() {
self::assertEmpty($sutEmpty->getUploadedFiles());
}

public function testWithUploadedFilesEmptyToFull() {
$sutEmpty = self::getServerRequest(
"post",
"/example",
[],
[],
[
"files" => [],
]
);
self::assertEmpty($sutEmpty->getUploadedFiles());

$file1 = self::createMock(FileUpload::class);
$file2 = self::createMock(FileUpload::class);

$sutFull = $sutEmpty->withUploadedFiles([
$file1,
$file2,
]);
self::assertCount(2, $sutFull->getUploadedFiles());
}

protected function getServerRequest(
string $method = null,
string $uri = null,
Expand Down Expand Up @@ -245,6 +268,15 @@ protected function getMockInput(
$mock->method("getAll")
->with(Input::DATA_FILES)
->willReturn($fileUploadParameters);
$mock->method("add")
->willReturnCallback(function(string $key, InputDatum $datum, string $method)use(&$fileArray) {
if($method === Input::DATA_FILES) {
/** @var FileUpload $datum */
$fileArray[$key] = [
"name" => $datum->getClientFilename()
];
}
});
return $mock;
}

Expand Down

0 comments on commit b886e94

Please sign in to comment.