function it_throws_an_exception_if_reference_data_does_not_exist($attrValidatorHelper, $repositoryResolver, ObjectRepository $repository, ProductInterface $product, AttributeInterface $attribute)
 {
     $attribute->getReferenceDataName()->willReturn('customMaterials');
     $attribute->getCode()->willReturn('lace_fabric');
     $attrValidatorHelper->validateLocale(Argument::cetera())->shouldBeCalled();
     $attrValidatorHelper->validateScope(Argument::cetera())->shouldBeCalled();
     $repositoryResolver->resolve('customMaterials')->willReturn($repository);
     $repository->findOneBy(['code' => 'hulk_retriever'])->willReturn(null);
     $exception = InvalidArgumentException::validEntityCodeExpected('lace_fabric', 'code', 'No reference data "customMaterials" with code "hulk_retriever" has been found', 'setter', 'reference data', 'hulk_retriever');
     $this->shouldThrow($exception)->during('setAttributeData', [$product, $attribute, 'hulk_retriever', ['locale' => 'fr_FR', 'scope' => 'mobile']]);
 }
 /**
  * {@inheritdoc}
  *
  * Expected data input format: "option_code"
  */
 public function setAttributeData(ProductInterface $product, AttributeInterface $attribute, $data, array $options = [])
 {
     $options = $this->resolver->resolve($options);
     $this->checkLocaleAndScope($attribute, $options['locale'], $options['scope'], 'text');
     $this->checkData($attribute, $data);
     if (null === $data) {
         $option = null;
     } else {
         $option = $this->attrOptionRepository->findOneBy(['code' => $data, 'attribute' => $attribute]);
         if (null === $option) {
             throw InvalidArgumentException::validEntityCodeExpected($attribute->getCode(), 'code', 'The option does not exist', 'setter', 'simple select', $data);
         }
     }
     $this->setOption($product, $attribute, $option, $options['locale'], $options['scope']);
 }
 /**
  * {@inheritdoc}
  */
 public function setAttributeData(ProductInterface $product, AttributeInterface $attribute, $data, array $options = [])
 {
     $this->checkLocaleAndScope($attribute, $options['locale'], $options['scope'], 'reference data');
     $this->checkData($attribute, $data);
     if (empty($data)) {
         $referenceData = null;
     } else {
         $repository = $this->repositoryResolver->resolve($attribute->getReferenceDataName());
         $referenceData = $repository->findOneBy(['code' => $data]);
         if (null === $referenceData) {
             throw InvalidArgumentException::validEntityCodeExpected($attribute->getCode(), 'code', sprintf('No reference data "%s" with code "%s" has been found', $attribute->getReferenceDataName(), $data), 'setter', 'reference data', $data);
         }
     }
     $this->setReferenceData($attribute, $product, $referenceData, $options['locale'], $options['scope']);
 }
 /**
  * @param AttributeInterface $attribute
  * @param string             $value
  *
  * @return int
  */
 protected function valueCodesToIds(AttributeInterface $attribute, $value)
 {
     try {
         $value = $this->idsResolver->resolve($attribute->getReferenceDataName(), $value);
     } catch (\LogicException $e) {
         throw InvalidArgumentException::validEntityCodeExpected($attribute->getCode(), 'code', $e->getMessage(), 'setter', 'reference data', implode(',', $value));
     }
     return $value;
 }
 function it_throws_an_error_if_the_attribute_data_option_does_not_exist(AttributeInterface $attribute, ProductInterface $product)
 {
     $attribute->getCode()->willReturn('attributeCode');
     $data = 'unknown code';
     $this->shouldThrow(InvalidArgumentException::validEntityCodeExpected('attributeCode', 'code', 'The option does not exist', 'setter', 'simple select', $data))->duringSetAttributeData($product, $attribute, $data, ['locale' => 'fr_FR', 'scope' => 'mobile']);
 }