/**
  * {@inheritdoc}
  */
 public function getVariant(VariableInterface $subject)
 {
     if ($subject->getVariants()->isEmpty()) {
         return null;
     }
     return $subject->getVariants()->first();
 }
 /**
  * @param OptionValueInterface[] $value
  *
  * @return null|VariantInterface
  */
 private function matches($value)
 {
     foreach ($this->variable->getVariants() as $variant) {
         foreach ($value as $option) {
             if (null === $option || !$variant->hasOption($option)) {
                 continue 2;
             }
         }
         return $variant;
     }
     return;
 }
 /**
  * @param OptionValueInterface[] $value
  *
  * @return null|VariantInterface
  */
 private function matches($value)
 {
     foreach ($this->variable->getVariants() as $variant) {
         $matches = true;
         foreach ($value as $option) {
             if (!$variant->hasOption($option)) {
                 $matches = false;
             }
         }
         if ($matches) {
             return $variant;
         }
     }
     return null;
 }
 /**
  * @param VariantInterface  $variant
  * @param VariableInterface $variable
  *
  * @return bool
  */
 private function matches(VariantInterface $variant, VariableInterface $variable)
 {
     foreach ($variable->getVariants() as $existingVariant) {
         if ($variant === $existingVariant) {
             continue;
         }
         $matches = true;
         foreach ($variant->getOptions() as $option) {
             if (!$existingVariant->hasOption($option)) {
                 $matches = false;
             }
         }
         if ($matches) {
             return true;
         }
     }
     return false;
 }
 function let(VariableInterface $variable, VariantInterface $variant)
 {
     $variable->getVariants()->shouldBeCalled()->willReturn([$variant]);
     $this->beConstructedWith($variable);
 }
 function it_returns_null_if_first_variant_is_not_definied(VariableInterface $product, Collection $variants)
 {
     $product->getVariants()->willReturn($variants);
     $variants->isEmpty()->willReturn(true);
     $this->getVariant($product)->shouldReturn(null);
 }
 /**
  * @param VariableInterface $variable
  */
 public function __construct(VariableInterface $variable)
 {
     parent::__construct($variable->getVariants(), 'name', [], null, 'id');
 }
 function it_should_not_reverse_transform_variable_with_variants_if_options_are_missing(VariableInterface $variable, VariantInterface $variant)
 {
     $variable->getVariants()->willReturn([$variant]);
     $this->reverseTransform([null])->shouldReturn(null);
 }
Example #9
0
 /**
  * Constructor.
  *
  * @param VariableInterface $variable
  */
 public function __construct(VariableInterface $variable)
 {
     parent::__construct($variable->getVariants(), 'presentation', array(), null, 'id');
 }
 function it_should_not_reverse_transform_variable_with_variants_if_options_not_match(VariableInterface $variable, VariantInterface $variant, OptionValueInterface $optionValue)
 {
     $variable->getVariants()->willReturn(array($variant));
     $variant->hasOption($optionValue)->willReturn(false);
     $this->reverseTransform(array($optionValue))->shouldReturn(null);
 }