Exemplo n.º 1
0
 function it_generates_variants_for_every_possible_permutation_of_an_objects_options_and_option_values(FactoryInterface $variantFactory, OptionInterface $colorOption, OptionInterface $sizeOption, OptionValue $blackColor, OptionValue $largeSize, OptionValue $mediumSize, OptionValue $redColor, OptionValue $smallSize, OptionValue $whiteColor, SetBuilderInterface $setBuilder, VariableInterface $productVariable, VariantInterface $permutationVariant)
 {
     $productVariable->hasOptions()->willReturn(true);
     $productVariable->getOptions()->willReturn([$colorOption, $sizeOption]);
     $colorOption->getValues()->willReturn([$blackColor, $whiteColor, $redColor]);
     $sizeOption->getValues()->willReturn([$smallSize, $mediumSize, $largeSize]);
     $blackColor->getId()->willReturn('black1');
     $whiteColor->getId()->willReturn('white2');
     $redColor->getId()->willReturn('red3');
     $smallSize->getId()->willReturn('small4');
     $mediumSize->getId()->willReturn('medium5');
     $largeSize->getId()->willReturn('large6');
     $setBuilder->build([['black1', 'white2', 'red3'], ['small4', 'medium5', 'large6']])->willReturn([['black1', 'small4'], ['black1', 'medium5'], ['black1', 'large6'], ['white2', 'small4'], ['white2', 'medium5'], ['white2', 'large6'], ['red3', 'small4'], ['red3', 'medium5'], ['red3', 'large6']]);
     $variantFactory->createNew()->willReturn($permutationVariant);
     $permutationVariant->setObject($productVariable)->shouldBeCalled();
     $permutationVariant->addOption(Argument::type('Sylius\\Component\\Variation\\Model\\OptionValue'))->shouldBeCalled();
     $productVariable->addVariant($permutationVariant)->shouldBeCalled();
     $this->generate($productVariable);
 }
Exemplo n.º 2
0
    function it_generates_variants_for_every_possible_permutation_of_an_objects_options_and_option_values(
        VariableInterface $productVariable,
        RepositoryInterface $variantRepository,
        SetBuilderInterface $setBuilder,
        OptionInterface $colorOption, OptionInterface $sizeOption,
        OptionValue $blackColor, OptionValue $whiteColor, OptionValue $redColor,
        OptionValue $smallSize, OptionValue $mediumSize, OptionValue $largeSize,
        VariantInterface $masterVariant, VariantInterface $permutationVariant
    ) {
        $productVariable->hasOptions()->willReturn(true);

        $productVariable->getOptions()->willReturn(array($colorOption, $sizeOption));

        $colorOption->getValues()->willReturn(array($blackColor, $whiteColor, $redColor));
        $sizeOption->getValues()->willReturn(array($smallSize, $mediumSize, $largeSize));

        $blackColor->getId()->willReturn('black1');
        $whiteColor->getId()->willReturn('white2');
        $redColor->getId()->willReturn('red3');
        $smallSize->getId()->willReturn('small4');
        $mediumSize->getId()->willReturn('medium5');
        $largeSize->getId()->willReturn('large6');

        $setBuilder->build(array(
            array('black1', 'white2', 'red3'),
            array('small4', 'medium5', 'large6')
        ))->willReturn(array(
            array('black1', 'small4'),
            array('black1', 'medium5'),
            array('black1', 'large6'),
            array('white2', 'small4'),
            array('white2', 'medium5'),
            array('white2', 'large6'),
            array('red3', 'small4'),
            array('red3', 'medium5'),
            array('red3', 'large6'),
        ));

        $productVariable->getMasterVariant()->willReturn($masterVariant);

        $variantRepository->createNew()->willReturn($permutationVariant);
        $permutationVariant->setObject($productVariable)->shouldBeCalled();
        $permutationVariant->setDefaults($masterVariant)->shouldBeCalled();
        $permutationVariant->addOption(Argument::type('Sylius\Component\Variation\Model\OptionValue'))->shouldBeCalled();
        $productVariable->addVariant($permutationVariant)->shouldBeCalled();

        $this->generate($productVariable);
    }