/** * @param UploadedFileInterface[] $uploadedFiles * @param string $path * @return File[] */ private function createFiles(array $uploadedFiles, string $path) : array { $files = []; foreach ($uploadedFiles as $uploadedFile) { $files[] = $file = $this->fileRepository->fromInput(substr($uploadedFile->getClientFilename(), 0, 92), $path, $uploadedFile->getClientMediaType(), $uploadedFile->getStream()); $this->fileRepository->createFromUpload($file); } return $files; }
public function it_can_handle_exception_during_request(RequestInterface $request, UploadedFileInterface $file) { $path = '/path/To/a'; $file->getClientFilename()->willReturn($name = 'file.ext'); $file->getClientMediaType()->willReturn($mime = 'text/xml'); $file->getStream()->willReturn($stream = tmpfile()); $files = [$file]; $request->offsetGet('path')->willReturn($path); $request->offsetGet('files')->willReturn($files); $request->getAcceptContentType()->willReturn('application/json'); $this->fileRepository->fromInput($name, $path, $mime, $stream)->willThrow(new \RuntimeException()); $this->shouldThrow(ResponseException::class)->duringExecuteRequest($request); }