function it_validates_attribute_value_based_on_their_type($attributeTypesRegistry, AttributeInterface $attribute, AttributeTypeInterface $attributeType, AttributeValueInterface $attributeValue, ValidAttributeValue $attributeValueConstraint)
 {
     $attributeValue->getType()->willReturn(TextAttributeType::TYPE);
     $attributeTypesRegistry->get('text')->willReturn($attributeType);
     $attributeValue->getAttribute()->willReturn($attribute);
     $attribute->getConfiguration()->willReturn(array('min' => 2, 'max' => 255));
     $attributeType->validate($attributeValue, Argument::any(ExecutionContextInterface::class), array('min' => 2, 'max' => 255))->shouldBeCalled();
     $this->validate($attributeValue, $attributeValueConstraint);
 }
 function it_builds_options_base_on_product_attribute(FormEvent $event, Form $form, AttributeValueInterface $productAttribute, Form $valueField, $formFactory)
 {
     $productAttribute->getType()->willReturn('choice');
     $productAttribute->getConfiguration()->willReturn(array('choices' => array('red' => 'Red', 'blue' => 'Blue')));
     $productAttribute->getName()->willReturn('My name');
     $event->getData()->willReturn($productAttribute);
     $event->getForm()->willReturn($form);
     $formFactory->createNamed('value', 'choice', null, array('label' => 'My name', 'auto_initialize' => false, 'choices' => array('red' => 'Red', 'blue' => 'Blue')))->willReturn($valueField)->shouldBeCalled();
     $form->remove('attribute')->shouldBeCalled()->willReturn($form);
     $form->add($valueField)->shouldBeCalled()->willReturn($form);
     $this->buildForm($event);
 }
 /**
  * Verify value before set to form.
  *
  * @param AttributeValueInterface $attributeValue
  */
 protected function verifyValue(AttributeValueInterface $attributeValue)
 {
     switch ($attributeValue->getType()) {
         case AttributeTypes::CHECKBOX:
             if (!is_bool($attributeValue->getValue())) {
                 $attributeValue->setValue(false);
             }
             break;
         case AttributeTypes::MONEY:
         case AttributeTypes::NUMBER:
         case AttributeTypes::PERCENTAGE:
             if (!is_numeric($attributeValue->getValue())) {
                 $attributeValue->setValue(null);
             }
             break;
     }
 }