/**
  * {@inheritdoc}
  */
 public function addData($data)
 {
     $backendType = $this->attribute->getBackendType();
     if ($this->attribute->isBackendTypeReferenceData()) {
         $backendType = $this->attribute->getReferenceDataName();
     }
     if (substr($backendType, -1, 1) === 's') {
         $backendType = substr($backendType, 0, strlen($backendType) - 1);
     }
     $name = 'add' . ucfirst($backendType);
     return $this->{$name}($data);
 }
 function it_sets_the_locale_and_scope_when_denormalizing_values($serializer, AttributeInterface $attribute)
 {
     $attribute->getAttributeType()->willReturn('pim_catalog_number');
     $attribute->getBackendType()->willReturn('decimal');
     $attribute->isBackendTypeReferenceData()->willReturn(false);
     $attribute->isLocalizable()->willReturn(true);
     $attribute->isScopable()->willReturn(true);
     $serializer->denormalize(1, 'pim_catalog_number', 'json', Argument::type('array'))->shouldBeCalled()->willReturn(1);
     $value = $this->denormalize(['data' => 1, 'locale' => 'en_US', 'scope' => 'ecommerce'], 'Pim\\Bundle\\CatalogBundle\\Model\\ProductValue', 'json', ['attribute' => $attribute]);
     $value->shouldBeAnInstanceOf('Pim\\Bundle\\CatalogBundle\\Model\\ProductValue');
     $value->getData()->shouldReturn(1);
     $value->getLocale()->shouldReturn('en_US');
     $value->getScope()->shouldReturn('ecommerce');
 }
 function it_adds_a_violation_when_validating_product_in_groups_with_non_unique_combination_of_axis_attributes($context, $productRepository, GroupInterface $tShirtVariantGroup, ProductInterface $redTShirtProduct, AttributeInterface $sizeAttribute, AttributeInterface $colorAttribute, ProductValueInterface $sizeProductValue, ProductValueInterface $colorProductValue, ProductInterface $redTShirtProduct2, UniqueVariantAxis $uniqueVariantAxisConstraint, ConstraintViolationBuilderInterface $violation)
 {
     $redTShirtProduct->getVariantGroup()->willReturn($tShirtVariantGroup);
     $tShirtVariantGroup->getId()->willReturn(1);
     $tShirtVariantGroup->getLabel()->willReturn('TShirts');
     $tShirtVariantGroup->getAxisAttributes()->willReturn([$sizeAttribute, $colorAttribute]);
     $sizeAttribute->getCode()->willReturn('size');
     $sizeAttribute->isBackendTypeReferenceData()->willReturn(true);
     $sizeAttribute->getReferenceDataName()->willReturn('ref_size');
     $colorAttribute->getCode()->willReturn('color');
     $colorAttribute->isBackendTypeReferenceData()->willReturn(true);
     $colorAttribute->getReferenceDataName()->willReturn('ref_color');
     $redTShirtProduct->getValue('size')->willReturn($sizeProductValue);
     $redTShirtProduct->getValue('color')->willReturn($colorProductValue);
     $redTShirtProduct->getId()->willReturn(1);
     $sizeProductValue->getData()->willReturn('XL');
     $sizeProductValue->getOption()->willReturn(null);
     $colorProductValue->getData()->willReturn('Red');
     $colorProductValue->getOption()->willReturn(null);
     $criteria = [['attribute' => $sizeAttribute, 'referenceData' => ['name' => 'ref_size', 'data' => 'XL']], ['attribute' => $colorAttribute, 'referenceData' => ['name' => 'ref_color', 'data' => 'Red']]];
     $productRepository->findAllForVariantGroup($tShirtVariantGroup, $criteria)->shouldBeCalled()->willReturn([$redTShirtProduct2]);
     $context->buildViolation('Group "%variant group%" already contains another product with values "%values%"', ['%variant group%' => 'TShirts', '%values%' => 'size: XL, color: Red'])->shouldBeCalled()->willReturn($violation);
     $this->validate($redTShirtProduct, $uniqueVariantAxisConstraint);
 }