예제 #1
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')]);
 }
예제 #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);
 }
예제 #3
0
 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;
     }
 }
예제 #4
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 . '"');
 }
예제 #5
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);
 }
예제 #6
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;
 }