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')]); }
public function determineImageFormat(File $file) : string { preg_match(self::MIME_PATTERN, $file->getMimeType()->toString(), $matches); $imageMimeType = $matches[1] ?? 'none'; if (in_array($imageMimeType, ['jpg', 'jpe', 'jpeg'], true)) { return 'jpeg'; } elseif (in_array($imageMimeType, ['png', 'gif'], true)) { return $imageMimeType; } throw new RuntimeException('Invalid image type, cannot edit: ' . $file->getMimeType()->toString()); }
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); }
public function updateMetaData(File $file) { $this->pdo->beginTransaction(); try { $query = $this->executeSql(' UPDATE files SET name = :name, path = :path, mime_type = :mime_type WHERE file_uuid = :file_uuid ', ['file_uuid' => $file->getUuid()->getBytes(), 'name' => $file->getName()->toString(), 'path' => $file->getPath()->toString(), 'mime_type' => $file->getMimeType()->toString()]); // When at least one of the fields changes, the rowCount will be 1 and an update occurred if ($query->rowCount() === 1) { $this->objectRepository->update(File::TYPE, $file->getUuid()); $file->metaDataSetUpdateTimestamp(new \DateTimeImmutable()); } $this->pdo->commit(); } catch (\Throwable $exception) { $this->pdo->rollBack(); throw $exception; } }
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); }
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 createImage(File $file, $imageContents) : File { $newFile = new File(Uuid::uuid4(), $file->getName(), $file->getPath(), $file->getMimeType(), $imageContents); $this->fileRepository->createFromUpload($newFile); return $newFile; }