function let(UploadedArchiveFactory $uploadedArchiveFactory, UploadProviderRegistry $uploadProviderRegistry, ArchiveRepository $archiveRepository, UploadedArchiveRepository $uploadedArchiveRepository, Archive $archive, UploadProvider $provider, UploadedArchive $uploadedArchive, UploadedArchiveFactory $uploadedArchiveFactory)
 {
     $archiveRepository->findByName('myArchiveName')->willReturn($archive);
     $uploadProviderRegistry->get('myProvider1')->willReturn($provider);
     $archive->getFiles()->willReturn([new ArchiveFile('/home/cocoders/aaa/a.jpg')]);
     $provider->upload('myArchiveName', ['/home/cocoders/aaa/a.jpg'])->willReturn();
     $uploadedArchiveFactory->create($archive, [$provider])->willReturn($uploadedArchive);
     $archiveRepository->add($archive)->willReturn();
     $archive->upload()->willReturn();
     $uploadedArchiveRepository->add($uploadedArchive)->willReturn();
     $this->beConstructedWith($uploadedArchiveFactory, $uploadProviderRegistry, $archiveRepository, $uploadedArchiveRepository);
 }
Exemplo n.º 2
0
 public function execute(UploadArchiveRequest $request)
 {
     $archive = $this->archiveRepository->findByName($request->archiveName);
     if (!$archive) {
         $this->archiveNotFound($request->archiveName);
         return;
     }
     $archiveFilePaths = array_map(function (ArchiveFile $archiveFile) {
         return $archiveFile->getPath();
     }, $archive->getFiles());
     $providers = [];
     foreach ($request->providersNames as $providerName) {
         $provider = $this->uploadProviderRegistry->get($providerName);
         $provider->upload($request->archiveName, $archiveFilePaths);
         $providers[] = $provider;
     }
     $archive->upload();
     $uploadedArchive = $this->uploadedArchiveFactory->create($archive, $providers);
     $this->uploadedArchiveRepository->add($uploadedArchive);
     $this->archiveRepository->add($archive);
     $this->archiveUploaded($request->archiveName);
 }