function it_normalizes_a_file_for_versioning(FileInfoInterface $fileInfo)
 {
     $fileInfo->getKey()->willReturn('key/of/file.txt');
     $fileInfo->getOriginalFilename()->willReturn('the file.txt');
     $fileInfo->getHash()->willReturn('98s7qf987a6f4sdqf');
     $this->normalize($fileInfo)->shouldReturn(['filePath' => 'key/of/file.txt', 'originalFilename' => 'the file.txt', 'hash' => '98s7qf987a6f4sdqf']);
 }
 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_returns_flat_data_with_media($channelManager, Filesystem $filesystem, ChannelInterface $channel, LocaleInterface $locale, ProductInterface $product, FileInfoInterface $media1, FileInfoInterface $media2, ProductValueInterface $value1, ProductValueInterface $value2, AttributeInterface $attribute, ProductValueInterface $identifierValue, AttributeInterface $identifierAttribute, $serializer, $productBuilder)
 {
     $localeCodes = ['en_US'];
     $channel->getLocales()->willReturn(new ArrayCollection([$locale]));
     $channel->getLocaleCodes()->willReturn($localeCodes);
     $productBuilder->addMissingProductValues($product, [$channel], [$locale])->shouldBeCalled();
     $media1->getKey()->willReturn('key/to/media1.jpg');
     $media2->getKey()->willReturn('key/to/media2.jpg');
     $value1->getAttribute()->willReturn($attribute);
     $value1->getMedia()->willReturn($media1);
     $value2->getAttribute()->willReturn($attribute);
     $value2->getMedia()->willReturn($media2);
     $attribute->getAttributeType()->willReturn('pim_catalog_image');
     $product->getValues()->willReturn([$value1, $value2, $identifierValue]);
     $identifierValue->getAttribute()->willReturn($identifierAttribute);
     $identifierAttribute->getAttributeType()->willReturn('pim_catalog_identifier');
     $product->getIdentifier()->willReturn($identifierValue);
     $identifierValue->getData()->willReturn('data');
     $filesystem->has('key/to/media1.jpg')->willReturn(true);
     $filesystem->has('key/to/media2.jpg')->willReturn(true);
     $serializer->normalize($media1, 'flat', ['field_name' => 'media', 'prepare_copy' => true, 'value' => $value1])->willReturn(['normalized_media1']);
     $serializer->normalize($media2, 'flat', ['field_name' => 'media', 'prepare_copy' => true, 'value' => $value2])->willReturn(['normalized_media2']);
     $serializer->normalize($product, 'flat', ['scopeCode' => 'foobar', 'localeCodes' => $localeCodes, 'decimal_separator' => '.', 'date_format' => 'yyyy-MM-dd'])->willReturn(['normalized_product']);
     $channelManager->getChannelByCode('foobar')->willReturn($channel);
     $this->setChannel('foobar');
     $this->process($product)->shouldReturn(['media' => [['normalized_media1'], ['normalized_media2']], 'product' => ['normalized_product']]);
 }
 function it_normalizes_media(FileInfoInterface $fileInfo)
 {
     $fileInfo->getKey()->willReturn('key/of/the/file.pdf');
     $fileInfo->getOriginalFilename()->willReturn('myfile.pdf');
     $fileInfo->getId()->willReturn(152);
     $this->normalize($fileInfo, 'mongodb_json', [])->shouldReturn(['id' => 152, 'key' => 'key/of/the/file.pdf', 'originalFilename' => 'myfile.pdf']);
 }
 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']]]);
 }
 function it_returns_flat_data_with_media($channelManager, Filesystem $filesystem, ChannelInterface $channel, ProductInterface $product, FileInfoInterface $media1, FileInfoInterface $media2, ProductValueInterface $value1, ProductValueInterface $value2, AttributeInterface $attribute, ProductValueInterface $identifierValue, AttributeInterface $identifierAttribute, $serializer)
 {
     $media1->getKey()->willReturn('key/to/media1.jpg');
     $media2->getKey()->willReturn('key/to/media2.jpg');
     $value1->getAttribute()->willReturn($attribute);
     $value1->getMedia()->willReturn($media1);
     $value2->getAttribute()->willReturn($attribute);
     $value2->getMedia()->willReturn($media2);
     $attribute->getAttributeType()->willReturn('pim_catalog_image');
     $product->getValues()->willReturn([$value1, $value2, $identifierValue]);
     $identifierValue->getAttribute()->willReturn($identifierAttribute);
     $identifierAttribute->getAttributeType()->willReturn('pim_catalog_identifier');
     $product->getIdentifier()->willReturn($identifierValue);
     $identifierValue->getData()->willReturn('data');
     $filesystem->has('key/to/media1.jpg')->willReturn(true);
     $filesystem->has('key/to/media2.jpg')->willReturn(true);
     $serializer->normalize($media1, 'flat', ['field_name' => 'media', 'prepare_copy' => true, 'value' => $value1])->willReturn(['normalized_media1']);
     $serializer->normalize($media2, 'flat', ['field_name' => 'media', 'prepare_copy' => true, 'value' => $value2])->willReturn(['normalized_media2']);
     $serializer->normalize($product, 'flat', ['scopeCode' => 'foobar', 'localeCodes' => ''])->willReturn(['normalized_product']);
     $channelManager->getChannelByCode('foobar')->willReturn($channel);
     $this->setChannel('foobar');
     $this->process($product)->shouldReturn(['media' => [['normalized_media1'], ['normalized_media2']], 'product' => ['normalized_product']]);
 }
 function it_normalizes_a_file(FileInfoInterface $fileInfo)
 {
     $fileInfo->getKey()->willReturn('key/of/file.txt');
     $fileInfo->getOriginalFilename()->willReturn('original file name.txt');
     $this->normalize($fileInfo, Argument::cetera())->shouldReturn(['filePath' => 'key/of/file.txt', 'originalFilename' => 'original file name.txt']);
 }
 function it_normalizes_file_info(FileInfoInterface $fileInfo)
 {
     $fileInfo->getKey()->willReturn('f/2/e/6/f2e6674e076ad6fafa12012e8fd026acdc70f814_fileA.txt');
     $this->normalize($fileInfo, 'standard')->shouldReturn('f/2/e/6/f2e6674e076ad6fafa12012e8fd026acdc70f814_fileA.txt');
 }
 function it_normalizes_a_file_for_versioning(FileInfoInterface $fileInfo)
 {
     $fileInfo->getKey()->willReturn('key/of/file.txt');
     $this->normalize($fileInfo, null, ['versioning' => true, 'field_name' => 'picture'])->shouldReturn(['picture' => 'key/of/file.txt']);
 }