function let(ChannelManager $channelManager, MediaManager $mediaManager, ProductValueNormalizer $productValueNormalizer, CategoryMappingManager $categoryMappingManager, AssociationTypeManager $associationTypeManager, MappingCollection $storeViewMapping, MappingCollection $categoryMapping, MappingCollection $attributeMapping, Product $product, ProductValue $productValue, ProductValue $imageValue, Channel $channel, Locale $localeFR, Locale $localeEN, Category $category) { $this->beConstructedWith($channelManager, $mediaManager, $productValueNormalizer, $categoryMappingManager, $associationTypeManager, 1, 4, 'currency', 'magento_url'); $this->globalContext = ['attributeSetId' => 0, 'magentoAttributes' => [], 'magentoAttributesOptions' => [], 'storeViewMapping' => $storeViewMapping, 'magentoStoreViews' => [['code' => 'fr_fr']], 'defaultLocale' => 'default_locale', 'website' => 'website', 'channel' => 'channel', 'categoryMapping' => $categoryMapping, 'attributeCodeMapping' => $attributeMapping, 'create' => true, 'pimGrouped' => 'pim_grouped', 'created_date' => new \DateTime(), 'updated_date' => new \DateTime(), 'defaultStoreView' => 'default', 'smallImageAttribute' => 'small_image_attribute', 'baseImageAttribute' => 'image_attribute', 'thumbnailAttribute' => 'image_attribute']; $attributeMapping->getTarget('visibility')->willReturn('visibility'); $attributeMapping->getTarget('created_at')->willReturn('created_at'); $attributeMapping->getTarget('updated_at')->willReturn('updated_at'); $attributeMapping->getTarget('status')->willReturn('status'); $attributeMapping->getTarget('categories')->willReturn('categories'); $channelManager->getChannelByCode('channel')->willReturn($channel); $channel->getLocales()->willReturn([$localeEN, $localeFR]); $localeEN->getCode()->willReturn('default_locale'); $localeFR->getCode()->willReturn('fr_FR'); $channel->getCode()->willReturn('channel_code'); $channel->getCategory()->willReturn($category); $product->getCategories()->willReturn([$category]); $product->getIdentifier()->willReturn('sku-000'); $product->getCreated()->willReturn($this->globalContext['created_date']); $product->getUpdated()->willReturn($this->globalContext['updated_date']); $product->getValues()->willReturn(new ArrayCollection([$productValue, $imageValue])); $storeViewMapping->getTarget('default_locale')->willReturn('default_locale'); $storeViewMapping->getTarget('fr_FR')->willReturn('fr_fr'); $categoryMappingManager->getIdFromCategory($category, 'magento_url', $categoryMapping)->willReturn(2); $productValueNormalizer->normalize($productValue, Argument::cetera())->willReturn(['value' => 'productValueNormalized']); $productValueNormalizer->normalize($imageValue, Argument::cetera())->willReturn(null); }
function let(Group $group, Product $product1, Product $product2, Product $product3, Attribute $attribute1, Attribute $attribute2, AttributeOption $attributeOption11, AttributeOption $attributeOption12, AttributeOption $attributeOption21, AttributeOption $attributeOption22, ProductValue $productValueOption11, ProductValue $productValueOption12, ProductValue $productValueOption21, ProductValue $productValueOption22, ProductValue $productValuePrice1, ProductPrice $productPrice1, ProductValue $productValuePrice2, ProductPrice $productPrice2, ProductValue $productValuePrice3, ProductPrice $productPrice3, MappingCollection $attributeMapping) { $this->beConstructedWith('locale', 'currency'); $group->getAttributes()->willReturn([$attribute1, $attribute2]); //get attribute options $attribute1->getOptions()->willReturn([$attributeOption11, $attributeOption12]); $attribute1->getCode()->willReturn('attribute_1'); $attributeOption11->getAttribute()->willReturn($attribute1); $attributeOption11->getCode()->willReturn('attribute_1_option_1'); $productValueOption11->getData()->willReturn($attributeOption11); $attributeOption12->getAttribute()->willReturn($attribute1); $attributeOption12->getCode()->willReturn('attribute_1_option_2'); $productValueOption12->getData()->willReturn($attributeOption12); $attribute2->getOptions()->willReturn([$attributeOption21, $attributeOption22]); $attribute2->getCode()->willReturn('attribute_2'); $attributeOption21->getAttribute()->willReturn($attribute2); $attributeOption21->getCode()->willReturn('attribute_2_option_1'); $productValueOption21->getData()->willReturn($attributeOption21); $attributeOption22->getAttribute()->willReturn($attribute2); $attributeOption22->getCode()->willReturn('attribute_2_option_2'); $productValueOption22->getData()->willReturn($attributeOption22); //Get product prices $product1->getValue('price', 'locale')->willReturn($productValuePrice1); $product1->getIdentifier()->willReturn('product_1'); $productValuePrice1->getPrice('currency')->willReturn($productPrice1); $productPrice1->getData()->willReturn(5.0); $product2->getValue('price', 'locale')->willReturn($productValuePrice2); $product2->getIdentifier()->willReturn('product_2'); $productValuePrice2->getPrice('currency')->willReturn($productPrice2); $productPrice2->getData()->willReturn(15.0); $product3->getValue('price', 'locale')->willReturn($productValuePrice3); $product3->getIdentifier()->willReturn('product_3'); $productValuePrice3->getPrice('currency')->willReturn($productPrice3); $productPrice3->getData()->willReturn(10.0); $attributeMapping->getSource('attribute_1')->willReturn('attribute_1'); $attributeMapping->getSource('attribute_2')->willReturn('attribute_2'); $attributeMapping->getTarget('attribute_1')->willReturn('attribute_1'); $attributeMapping->getTarget('attribute_2')->willReturn('attribute_2'); }
function it_throws_an_exception_if_something_went_wrong_during_normalization($webservice, $attributeMappingMerger, $categoryMappingMerger, $productNormalizer, $mappingCollection, Product $product, Channel $channel, Family $family, MetricConverter $metricConverter, AbstractAttribute $skuAttribute, ProductValue $sku) { $categoryMappingMerger->getMapping()->willReturn($mappingCollection); $attributeMappingMerger->getMapping()->willReturn($mappingCollection); $product->getFamily()->shouldBeCalled()->willReturn($family); $family->getCode()->shouldBeCalled()->willReturn('family_code'); $webservice->getAttributeSetId('family_code')->shouldBeCalled()->willReturn('4'); $product->getIdentifier()->shouldBeCalled()->willReturn($sku); $sku->getData()->willReturn('sku-000'); $sku->getAttribute()->willReturn($skuAttribute); $skuAttribute->getCode()->willReturn('SKU'); $product->getId()->willReturn(12); $product->getLabel()->willReturn('my product'); $metricConverter->convert($product, $channel)->shouldBeCalled(); $productNormalizer->normalize(Argument::type('\\Pim\\Bundle\\CatalogBundle\\Model\\Product'), 'MagentoArray', Argument::type('array'))->shouldBeCalled()->willThrow('\\Pim\\Bundle\\MagentoConnectorBundle\\Normalizer\\Exception\\NormalizeException'); $this->shouldThrow('\\Akeneo\\Bundle\\BatchBundle\\Item\\InvalidItemException')->duringProcess($product); }
/** * @expectedException Pim\Bundle\CatalogBundle\Exception\MissingIdentifierException */ public function testThrowExceptionIfNoIdentifier() { $name = $this->getValueMock($this->getAttributeMock()); $this->product->addValue($name); $this->product->getIdentifier(); }
/** * {@inheritDoc} */ public function getIdentifier() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getIdentifier', array()); return parent::getIdentifier(); }