Beispiel #1
0
 /**
  * Handles the given command.
  *
  * @param UploadFileCommand $aCommand The command
  *
  * @throws FileAlreadyExistsException when file is already exists
  */
 public function __invoke(UploadFileCommand $aCommand)
 {
     $id = new FileId($aCommand->id());
     $file = $this->repository->fileOfId($id);
     if (null !== $file) {
         throw new FileAlreadyExistsException();
     }
     $name = new FileName($aCommand->name());
     if (true === $this->filesystem->has($name)) {
         throw new FileAlreadyExistsException();
     }
     $this->filesystem->write($name, $aCommand->uploadedFile());
     $file = $this->factory->build($id, $name, new FileMimeType($aCommand->mimeType()));
     $this->repository->persist($file);
 }
Beispiel #2
0
 function it_handles(UploadFileCommand $command, Filesystem $filesystem, FileRepository $repository, FileFactory $factory, File $file)
 {
     $command->id()->shouldBeCalled()->willReturn('file-id');
     $command->name()->shouldBeCalled()->willReturn('dummy-file-name.pdf');
     $command->uploadedFile()->shouldBeCalled()->willReturn('test-content');
     $command->mimeType()->shouldBeCalled()->willReturn('application/pdf');
     $id = new FileId('file-id');
     $name = new FileName('dummy-file-name.pdf');
     $mimeType = new FileMimeType('application/pdf');
     $repository->fileOfId($id)->shouldBeCalled()->willReturn(null);
     $filesystem->has($name)->shouldBeCalled()->willReturn(false);
     $filesystem->write($name, 'test-content')->shouldBeCalled();
     $factory->build($id, $name, $mimeType)->shouldBeCalled()->willReturn($file);
     $repository->persist($file)->shouldBeCalled();
     $this->__invoke($command);
 }