Example #1
0
 public function it_can_generate_an_image_response(ResponseInterface $response, File $file, ImageInterface $image)
 {
     $responseMock = 'i-am-not-really-an-image';
     $fileName = FileNameValue::get('image.png');
     $fileMimeType = MimeTypeValue::get('image/png');
     $response->offsetGet('image')->willReturn($image);
     $response->offsetGet('file')->willReturn($file);
     $file->getName()->willReturn($fileName);
     $file->getMimeType()->willReturn($fileMimeType);
     $this->imageEditor->output($file, $image)->willReturn($responseMock);
     $httpResponse = $this->generateResponse($response);
     $httpResponse->shouldHaveType(HttpResponse::class);
     $httpResponse->getStatusCode()->shouldReturn(200);
     $httpResponse->getHeaderLine('Content-Type')->shouldReturn($fileMimeType->toString());
     $httpResponse->getBody()->getContents()->shouldReturn($responseMock);
 }
Example #2
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 #3
0
 public function let()
 {
     $this->file = (new File(Uuid::uuid4(), FileNameValue::get('file.ext'), FilePathValue::get('/path/to'), MimeTypeValue::get('text/text'), tmpfile()))->metaDataSetInsertTimestamp(new \DateTimeImmutable())->metaDataSetUpdateTimestamp(new \DateTimeImmutable());
 }
Example #4
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 #5
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 #6
0
 public function it_can_change_its_mime_type()
 {
     $newMime = MimeTypeValue::get('text/html');
     $this->setMimeType($newMime)->shouldReturn($this);
     $this->getMimeType()->shouldReturn($newMime);
 }
Example #7
0
 private function getFileFromRow(array $row) : File
 {
     $uuid = Uuid::fromBytes($row['file_uuid']);
     return (new File($uuid, FileNameValue::get($row['name']), FilePathValue::get($row['path']), MimeTypeValue::get($row['mime_type']), $this->getFileStream($uuid)))->metaDataSetInsertTimestamp(new \DateTimeImmutable($row['created']))->metaDataSetUpdateTimestamp(new \DateTimeImmutable($row['updated']));
 }
Example #8
0
 public function it_will_roll_back_after_failed_update_file_meta_data(File $file)
 {
     $uuid = Uuid::uuid4();
     $name = FileNameValue::get('file.name');
     $path = FilePathValue::get('/uploads');
     $mime = MimeTypeValue::get('text/xml');
     $file->getUuid()->willReturn($uuid);
     $file->getName()->willReturn($name);
     $file->setName($name)->willReturn($file);
     $file->getPath()->willReturn($path);
     $file->getMimeType()->willReturn($mime);
     $this->pdo->beginTransaction()->shouldBeCalled();
     $this->pdo->prepare(new Argument\Token\StringContainsToken('UPDATE files'))->willThrow(new \RuntimeException());
     $this->objectRepository->update(File::TYPE, $uuid)->shouldNotBeCalled();
     $this->pdo->rollBack()->shouldBeCalled();
     $file->metaDataSetUpdateTimestamp(new Argument\Token\TypeToken(\DateTimeImmutable::class))->shouldNotBeCalled();
     $this->shouldThrow(\RuntimeException::class)->duringUpdateMetaData($file);
 }