루멘과 함께 파일 업로드 JSON API를 작성하고 phpunit API 테스트를 작성하려고합니다.루멘 5.5 JSON API 파일 업로드 테스트가 UploadedFile로 중단됩니다.
그래도 난 데 문제는 내가 진짜 이미지 ["file" => new UploadedFile(TestUtils::tempPath('test.jpg'), 'test.jpg', "image\jpeg", 100, null, true)]
같은 구성 및 $this->json('POST', '/chunk', $data);
를 통해 그것을 전송과 파일 업로드를 시뮬레이션하려고 마자 그것이을하기 때문에, 내가 업로드 된 파일에 아무것도 할 수 없다는 것입니다 배열과 나는 오류가 발생합니다 Call to a member function move() on array in ...
이상한게 내가 UploadedFile::fake()->image('test.jpg')
을 사용하면 그것은 내 요청을 망가 뜨리고 컨트롤러와 함께 보내는 다른 데이터는 사용할 수 없습니다.
컨트롤러의 파일 객체를 ddd하면 "array (0) {}"이 표시됩니다. 나는 그것이 UploadedFileObject를 사용하는 단위 테스트가 성공적으로 성공적으로 실행되기 때문에 json ('POST')을 통한 전송과 관련이 있다고 생각합니다. 나는 전체 요청을 dd는 경우
, 그것은 보여줍니다
["request"]=>
object(Symfony\Component\HttpFoundation\ParameterBag)#52 (1) {
["parameters":protected]=>
array(5) {
["chunkType"]=>
string(4) "flow"
["flowIdentifier"]=>
string(13) "Testing123Bnu"
["flowChunkNumber"]=>
int(1)
["flowTotalChunks"]=>
int(2)
["file"]=>
array(0) {
}
}
}
...
["files"]=>
object(Symfony\Component\HttpFoundation\FileBag)#71 (1) {
["parameters":protected]=>
array(0) {
}
}
...
["content":protected]=> string(103) "{(otherData..), "file":{}}"
나는이 문제를 회피하거나이 상황에서 파일 업로드를 테스트하고 시간 동안 검색 한 방법을 모른다. UploadedFile 생성자의 symfony 테스트 모드는 아무 효과가 없습니다. 여기
내 테스트입니다 :public function testChunkUpload_FlowChunk()
{
$data = [ (otherData)
"file" => new UploadedFile(TestUtils::tempPath('test.jpg'), 'test.jpg', "image\jpeg", 100, null, true)
//UploadedFile::fake()->image('test.jpg')
];
$this->assertFileExists(TestUtils::tempPath('test.jpg'));
$this->json('POST', '/chunk', $data);
$this->assertEquals(200, $this->response->status());
$this->assertEquals('application/json', $this->response->headers->get('Content-Type'));
}
그리고 여기 내 컨트롤러의 관련 방법 :
public function receiveChunk(Request $request){
if (! $request->has('chunkType')) {
return response()->json(["Invalid Chunk Type"], 400);
}
$data = $this->chunkNormalizer->normalizeInput($request->all());
$chunk = $this->chunkFactory->createChunk( (otherData)
$data['fileHandle']);
$this->fileAssembler->processChunk($chunk);
return response()->json(["Success"], 200);
}
그리고 오류가 processChunk에서 발생
public function processChunk(FileChunk $chunk){
...
$chunkName = "..." . ".chunk";
$fileHandle = $chunk->getFileHandle();
$fileHandle->move($this->assemblePath, $chunkName);
}
모든 아이디어는 것 크게 감사드립니다!