Example #1
0
 public function process(File $file, array $operations) : ImageInterface
 {
     $image = $this->imagine->read($file->getStream());
     foreach ($operations as $operation => $args) {
         $this->executeOperation($image, $operation, $args);
     }
     return $image;
 }
Example #2
0
 public function it_can_generate_a_response(ResponseInterface $response, File $file)
 {
     $fileName = 'file.ext';
     $mimeType = 'text/xml';
     $file->getStream()->willReturn(tmpfile());
     $file->getName()->willReturn(FileNameValue::get($fileName));
     $file->getMimeType()->willReturn(MimeTypeValue::get($mimeType));
     $response->offsetGet('data')->willReturn($file);
     $httpResponse = $this->generateResponse($response);
     $httpResponse->getHeaderLine('Content-Type')->shouldReturn($mimeType);
     $httpResponse->getHeaderLine('Content-Disposition')->shouldReturn('attachment; filename="' . $fileName . '"');
 }
Example #3
0
 public function it_can_execute_a_request(RequestInterface $request, File $file)
 {
     $path = '/path/to/a/file.ext';
     $filename = 'path.deux';
     $request->offsetGet('path')->willReturn($path);
     $request->offsetGet('filename')->willReturn($filename);
     $request->getAcceptContentType()->willReturn('*/*');
     $file->setName(FileNameValue::get($filename))->shouldBeCalled();
     $this->fileRepository->getByFullPath($path)->willReturn($file);
     $this->fileRepository->updateMetaData($file)->shouldBeCalled();
     $response = $this->executeRequest($request);
     $response->shouldHaveType(ResponseInterface::class);
     $response->getResponseName()->shouldReturn(RenameFileHandler::MESSAGE);
     $response['data']->shouldBe($file);
 }
Example #4
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 #5
0
 public function it_can_transform_file_to_array()
 {
     $attributes = $this->getAttributes($this->file);
     $attributes['name']->shouldBe($this->file->getName()->toString());
     $attributes['path']->shouldBe($this->file->getPath()->toString());
     $attributes['mime_type']->shouldBe($this->file->getMimeType()->toString());
     $attributes['meta']->shouldBe(['created' => $this->file->metaDataGetCreatedTimestamp()->format('c'), 'updated' => $this->file->metaDataGetUpdatedTimestamp()->format('c')]);
 }
Example #6
0
 public function it_can_output_the_result(File $file, ImageInterface $image)
 {
     $result = 'resultingimagestring';
     $file->getMimeType()->willReturn(MimeTypeValue::get('image/jpg'));
     $image->get('jpeg')->willReturn($result);
     $this->output($file, $image)->shouldReturn($result);
 }
Example #7
0
 public function delete(File $file)
 {
     $this->pdo->beginTransaction();
     try {
         if (!$this->fileSystem->delete($file->getUuid()->toString())) {
             throw new \RuntimeException('Failed to delete file');
         }
         $this->objectRepository->delete(File::TYPE, $file->getUuid());
         $this->pdo->commit();
     } catch (\Throwable $exception) {
         $this->pdo->rollBack();
         throw $exception;
     }
 }
Example #8
0
 public function it_can_will_error_and_roll_back_when_delete_fails(File $file)
 {
     $uuid = Uuid::uuid4();
     $file->getUuid()->willReturn($uuid);
     $this->pdo->beginTransaction()->shouldBeCalled();
     $this->fileSystem->delete($uuid->toString())->willReturn(false);
     $this->objectRepository->delete(File::TYPE, $uuid)->shouldNotBeCalled();
     $this->pdo->rollBack()->shouldBeCalled();
     $this->shouldThrow(\RuntimeException::class)->duringDelete($file);
 }
Example #9
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;
 }