/**
  * @param  Attribute            $attribute
  * @return array|mixed
  * @throws InvalidItemException
  */
 public function process($attribute)
 {
     $result = ['code' => $attribute->getCode(), 'labels' => array(), 'options' => array()];
     foreach ($attribute->getTranslations() as $trans) {
         $result['labels'][$trans->getLocale()] = $trans->getLabel();
     }
     foreach ($attribute->getOptions() as $attributeOption) {
         $result['options'][$attributeOption->getCode()] = $this->normalizeOption($attributeOption, $this->globalContext);
     }
     return $result;
 }
 function let(ChannelManager $channelManager, ProductNormalizer $productNormalizer, PriceMappingManager $priceMappingManager, MappingCollection $categoryMapping, MappingCollection $attributeMapping, MappingCollection $storeViewMapping, ProductInterface $product, Channel $channel, Locale $localeFR, Locale $localeEN, Group $group, Attribute $attribute)
 {
     $this->beConstructedWith($channelManager, $productNormalizer, $priceMappingManager, 4);
     $this->globalContext = ['attributeSetId' => 0, 'magentoAttributes' => ['attribute_code' => ['attribute_id' => 42]], 'magentoAttributesOptions' => [], 'storeViewMapping' => $storeViewMapping, 'magentoStoreViews' => [['code' => 'fr_fr']], 'defaultLocale' => 'default_locale', 'website' => 'website', 'channel' => 'channel', 'categoryMapping' => $categoryMapping, 'attributeCodeMapping' => $attributeMapping, 'create' => true, 'defaultStoreView' => 'default', 'smallImageAttribute' => 'smallImageAttr', 'baseImageAttribute' => 'baseImageAttr', 'thumbnailAttribute' => 'thumbnailAttr', 'pimGrouped' => 'grouped_product_code', 'urlKey' => false, 'skuFirst' => false];
     $productNormalizer->getNormalizedImages($product, 'conf-group_code', 'smallImageAttr', 'baseImageAttr', 'thumbnailAttr')->willReturn([]);
     $productNormalizer->getValues(Argument::cetera())->willReturn([ProductNormalizer::URL_KEY => 'my-url-key']);
     $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');
     $storeViewMapping->getTarget('default_locale')->willReturn('default_locale');
     $storeViewMapping->getTarget('fr_FR')->willReturn('fr_fr');
     $group->getId()->willReturn(44);
     $group->getCode()->willReturn('group_code');
     $product->getIdentifier()->willReturn('sku-000');
     $attribute->setCode('attribute_code');
     $group->getAttributes()->willReturn([$attribute]);
     $attribute->getCode()->willReturn('attribute_code');
     $attributeMapping->getTarget('attribute_code')->willReturn('attribute_code');
 }
 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');
 }
 /**
  * {@inheritDoc}
  */
 public function getCode()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getCode', array());
     return parent::getCode();
 }
 public function let(ObjectManager $objectManager, EntityRepository $entityRepository, Attribute $attribute)
 {
     $this->beConstructedWith($objectManager, 'Pim\\Bundle\\MagentoConnectorBundle\\Entity\\MagentoAttributeMapping');
     $objectManager->getRepository('Pim\\Bundle\\MagentoConnectorBundle\\Entity\\MagentoAttributeMapping')->willReturn($entityRepository);
     $attribute->getCode()->willReturn(12);
 }
 function it_raises_an_exception_if_an_error_occures_during_normalization_process($attributeMappingMerger, $clientParametersRegistry, $groupManager, $normalizerGuesser, $storeViewMappingMerger, $webservice, $webserviceGuesser, Attribute $attribute, AttributeNormalizer $attributeNormalizer, GroupRepository $groupRepository, MagentoSoapClientParameters $clientParameters, MappingCollection $attributeMapping, MappingCollection $storeViewMapping, Webservice $webservice)
 {
     $clientParametersRegistry->getInstance(Argument::cetera())->willReturn($clientParameters);
     $storeViewList = [0 => ['store_id' => '1', 'code' => 'default', 'website_id' => '1', 'group_id' => '1', 'name' => 'Default Store View', 'sort_order' => '0', 'is_active' => '1'], 1 => ['store_id' => '2', 'code' => 'fr_fr', 'website_id' => '1', 'group_id' => '1', 'name' => 'French Store View', 'sort_order' => '0', 'is_active' => '1']];
     $normalizerGuesser->getAttributeNormalizer($clientParameters)->willReturn($attributeNormalizer);
     $webserviceGuesser->getWebservice($clientParameters)->willReturn($webservice);
     $attribute->getCode()->willReturn('attribute_code');
     $storeViewMappingMerger->getMapping()->willReturn($storeViewMapping);
     $webservice->getAllAttributes()->willReturn([]);
     $webservice->getAllAttributesOptions()->willReturn([]);
     $attributeMappingMerger->getMapping()->willReturn($attributeMapping);
     $webservice->getStoreViewsList()->willReturn($storeViewList);
     $groupManager->getRepository()->willReturn($groupRepository);
     $groupRepository->getAxisAttributes()->willReturn([['code' => 'configurable_attribute_code']]);
     $attributeMapping->getTarget('attribute_code')->willReturn('attribute_code_mapped');
     $context = ['defaultLocale' => null, 'storeViewMapping' => $storeViewMapping, 'defaultStoreView' => 'default', 'magentoAttributes' => [], 'magentoAttributesOptions' => [], 'attributeCodeMapping' => $attributeMapping, 'magentoStoreViews' => $storeViewList, 'axisAttributes' => ['configurable_attribute_code'], 'create' => true];
     $attributeNormalizer->normalize($attribute, 'MagentoArray', $context)->willThrow(new InvalidItemException('Something goes horribly wrong!', [[]]));
     $this->shouldThrow(new InvalidItemException('Something goes horribly wrong!', [[]]))->during('process', [$attribute]);
 }