function it_normalizes_a_file_for_product_export($pathGenerator, ProductValueInterface $value, FileInfoInterface $fileInfo) { $pathGenerator->generate($value, Argument::any())->willReturn('path/to/export/file.txt'); $fileInfo->getKey()->willReturn('key/of/file.txt'); $fileInfo->getStorage()->willReturn(FileStorage::CATALOG_STORAGE_ALIAS); $this->normalize($fileInfo, null, ['identifier' => null, 'value' => $value, 'field_name' => 'picture'])->shouldReturn(['picture' => 'path/to/export/file.txt']); }
function it_allows_to_get_errors_if_the_copy_went_wrong($mediaFetcher, $filesystemProvider, $fileExporterPath, FileInfoInterface $fileInfo, FileInfoInterface $fileInfo2, ArrayCollection $productValuesCollection, \ArrayIterator $valuesIterator, ProductValueInterface $productValue, ProductValueInterface $productValue2, AttributeInterface $attribute, FilesystemInterface $filesystem) { $fileInfo->getStorage()->willReturn('storageAlias'); $fileInfo->getKey()->willReturn('a/b/c/d/product.jpg'); $fileInfo->getOriginalFilename()->willReturn('my product.jpg'); $fileInfo2->getStorage()->willReturn('storageAlias'); $fileInfo2->getKey()->willReturn('wrong-path.jpg'); $fileInfo2->getOriginalFilename()->willReturn('my-second-media.jpg'); $productValue->getAttribute()->willReturn($attribute); $productValue->getMedia()->willReturn($fileInfo); $productValue->getLocale()->willReturn('en_US'); $productValue->getScope()->willReturn(null); $productValue2->getAttribute()->willReturn($attribute); $productValue2->getMedia()->willReturn($fileInfo2); $productValue2->getLocale()->willReturn('fr_FR'); $productValue2->getScope()->willReturn('ecommerce'); $attribute->getAttributeType()->willReturn('pim_catalog_image'); $attribute->getCode()->willReturn('my_picture'); $productValuesCollection->getIterator()->willReturn($valuesIterator); $valuesIterator->rewind()->shouldBeCalled(); $valuesCount = 2; $valuesIterator->valid()->will(function () use(&$valuesCount) { return $valuesCount-- > 0; }); $valuesIterator->next()->shouldBeCalled(); $valuesIterator->current()->will(new ReturnPromise([$productValue, $productValue2])); $filesystemProvider->getFilesystem('storageAlias')->willReturn($filesystem); $mediaFetcher->fetch($filesystem, 'a/b/c/d/product.jpg', ['filePath' => $this->directory . 'files/the_sku/my_picture/en_US/', 'filename' => 'my product.jpg'])->willThrow(new FileTransferException()); $fileExporterPath->generate(['locale' => 'en_US', 'scope' => null], ['identifier' => 'the_sku', 'code' => 'my_picture'])->willReturn('files/the_sku/my_picture/en_US/'); $mediaFetcher->fetch($filesystem, 'wrong-path.jpg', ['filePath' => $this->directory . 'files/the_sku/my_picture/fr_FR/ecommerce/', 'filename' => 'my-second-media.jpg'])->willThrow(new \LogicException('Something went wrong.')); $fileExporterPath->generate(['locale' => 'fr_FR', 'scope' => 'ecommerce'], ['identifier' => 'the_sku', 'code' => 'my_picture'])->willReturn('files/the_sku/my_picture/fr_FR/ecommerce/'); $this->fetchAll($productValuesCollection, $this->directory, 'the_sku'); $this->getErrors()->shouldBeEqualTo([['message' => 'The media has not been found or is not currently available', 'media' => ['from' => 'a/b/c/d/product.jpg', 'to' => ['filePath' => $this->directory . 'files/the_sku/my_picture/en_US/', 'filename' => 'my product.jpg'], 'storage' => 'storageAlias']], ['message' => 'The media has not been copied. Something went wrong.', 'media' => ['from' => 'wrong-path.jpg', 'to' => ['filePath' => $this->directory . 'files/the_sku/my_picture/fr_FR/ecommerce/', 'filename' => 'my-second-media.jpg'], 'storage' => 'storageAlias']]]); }