public function updateContent(File $file) { if (!$this->fileSystem->putStream($file->getUuid()->toString(), $file->getStream())) { throw new \RuntimeException('Failed to update file content.'); } $this->objectRepository->update(File::TYPE, $file->getUuid()); $file->metaDataSetUpdateTimestamp(new \DateTimeImmutable()); }
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; }
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 . '"'); }
public function it_will_error_on_invalid_operation(File $file, ImageInterface $image) { $stream = tmpfile(); $file->getStream()->willReturn($stream); $this->imagine->read($stream)->willReturn($image); $this->shouldThrow(\RuntimeException::class)->duringProcess($file, ['nope' => []]); $this->shouldThrow(\RuntimeException::class)->duringProcess($file, ['resize' => []]); }
public function it_can_errors_on_upload_failure_with_update_file_content(File $file) { $uuid = Uuid::uuid4(); $stream = tmpfile(); $file->getUuid()->willReturn($uuid); $file->getStream()->willReturn($stream); $this->fileSystem->putStream($uuid->toString(), $stream)->willReturn(false); $this->objectRepository->update(File::TYPE, $uuid)->shouldNotBeCalled(); $this->shouldThrow(\RuntimeException::class)->duringUpdateContent($file); // cleanup fclose($stream); }