Example #1
0
 /**
  * @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;
 }
Example #2
0
 public function it_can_execute_a_request(RequestInterface $request, UploadedFileInterface $file, File $fileEntity)
 {
     $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)->willReturn($fileEntity);
     $this->fileRepository->createFromUpload($fileEntity)->shouldBeCalled();
     $response = $this->executeRequest($request);
     $response->shouldHaveType(ResponseInterface::class);
     $response->getResponseName()->shouldReturn(UploadFileHandler::MESSAGE);
     $response['data'][0]->shouldHaveType(File::class);
 }
Example #3
0
 public function it_can_create_an_image(File $oldFile)
 {
     $name = FileNameValue::get('oldName.jpg');
     $path = FilePathValue::get('/path/to/something');
     $mime = MimeTypeValue::get('image/jpg');
     $oldFile->getName()->willReturn($name);
     $oldFile->getPath()->willReturn($path);
     $oldFile->getMimeType()->willReturn($mime);
     $imageContents = tmpfile();
     $this->fileRepository->createFromUpload(new Argument\Token\TypeToken(File::class));
     $newImage = $this->createImage($oldFile, $imageContents);
     $newImage->getUuid()->shouldHaveType(Uuid::class);
     $newImage->getName()->shouldReturn($name);
     $newImage->getPath()->shouldReturn($path);
     $newImage->getMimeType()->shouldReturn($mime);
     $newImage->getStream()->shouldReturn($imageContents);
 }
Example #4
0
 public function createImage(File $file, $imageContents) : File
 {
     $newFile = new File(Uuid::uuid4(), $file->getName(), $file->getPath(), $file->getMimeType(), $imageContents);
     $this->fileRepository->createFromUpload($newFile);
     return $newFile;
 }