function it_should_not_add_violation_if_conflictual_variant_and_validated_one_are_the_same($variantRepository, VariantInterface $variant, $context) { $constraint = new VariantUnique(array('property' => 'presentation', 'message' => 'Variant with given presentation already exists')); $variant->getPresentation()->willReturn('111AAA'); $variantRepository->findOneBy(array('presentation' => '111AAA'))->willReturn($variant); $context->addViolationAt(Argument::any())->shouldNotBeCalled(); $this->validate($variant, $constraint); }
function it_should_add_violation_if_variant_with_given_same_options_already_exists(VariantInterface $variant, VariantInterface $existingVariant, VariableInterface $variable, OptionValueInterface $option, $context) { $constraint = new VariantCombination(['message' => 'Variant with given options already exists']); $variant->getObject()->willReturn($variable); $variant->getOptions()->willReturn(new ArrayCollection([$option->getWrappedObject()])); $existingVariant->hasOption($option)->willReturn(true); $variable->hasVariants()->willReturn(true); $variable->hasOptions()->willReturn(true); $variable->getVariants()->willReturn([$existingVariant]); $context->addViolation('Variant with given options already exists', Argument::any())->shouldBeCalled(); $this->validate($variant, $constraint); }
/** * @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 it_throws_exception_if_trying_to_inherit_values_from_non_master_variant(VariantInterface $variant) { $variant->isMaster()->willReturn(false); $this->shouldThrow('InvalidArgumentException')->duringSetDefaults($variant); }
/** * {@inheritdoc} */ public function setMasterVariant(BaseVariantInterface $masterVariant) { $masterVariant->setMaster(true); if (!$this->variants->contains($masterVariant)) { $masterVariant->setProduct($this); $this->variants->add($masterVariant); } return $this; }
/** * {@inheritdoc} */ public function setDefaults(VariantInterface $masterVariant) { if (!$masterVariant->isMaster()) { throw new \InvalidArgumentException('Cannot inherit values from non master variant.'); } if ($this->isMaster()) { throw new \LogicException('Master variant cannot inherit from another master variant.'); } }
function it_should_not_reverse_transform_variable_with_variants_if_options_not_match(VariableInterface $variable, VariantInterface $variant, OptionValueInterface $optionValue) { $variable->getVariants()->willReturn([$variant]); $variant->hasOption($optionValue)->willReturn(false); $this->reverseTransform([$optionValue])->shouldReturn(null); }