Completed
Push — 1.3 ( ea96f1...08f6de )
by Kamil
13:44
created

HasTaxonRuleUpdaterSpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace spec\Sylius\Component\Core\Promotion\Updater\Rule;
15
16
use Doctrine\ORM\EntityManagerInterface;
17
use PhpSpec\ObjectBehavior;
18
use Prophecy\Argument;
19
use Sylius\Component\Core\Model\PromotionInterface;
20
use Sylius\Component\Core\Model\TaxonInterface;
21
use Sylius\Component\Promotion\Model\PromotionRuleInterface;
22
use Sylius\Component\Resource\Repository\RepositoryInterface;
23
24
final class HasTaxonRuleUpdaterSpec extends ObjectBehavior
25
{
26
    function let(RepositoryInterface $promotionRuleRepository, EntityManagerInterface $manager): void
27
    {
28
        $this->beConstructedWith($promotionRuleRepository, $manager);
29
    }
30
31
    function it_removes_deleted_taxon_from_rules_configurations(
32
        RepositoryInterface $promotionRuleRepository,
33
        EntityManagerInterface $manager,
34
        PromotionRuleInterface $firstPromotionRule,
35
        PromotionRuleInterface $secondPromotionRule,
36
        PromotionInterface $promotion,
37
        TaxonInterface $taxon
38
    ): void {
39
        $taxon->getCode()->willReturn('toys');
40
41
        $promotionRuleRepository
42
            ->findBy(['type' => 'has_taxon'])
43
            ->willReturn([$firstPromotionRule, $secondPromotionRule])
44
        ;
45
        $firstPromotionRule->getConfiguration()->willReturn(['taxons' => ['mugs', 'toys']]);
46
        $secondPromotionRule->getConfiguration()->willReturn(['taxons' => ['mugs']]);
47
48
        $firstPromotionRule->getPromotion()->willReturn($promotion);
49
        $promotion->getCode()->willReturn('christmas');
50
51
        $firstPromotionRule->setConfiguration(['taxons' => ['mugs']])->shouldBeCalled();
52
        $secondPromotionRule->setConfiguration(Argument::any())->shouldNotBeCalled();
53
54
        $manager->flush()->shouldBeCalled();
55
56
        $this->updateAfterDeletingTaxon($taxon)->shouldReturn(['christmas']);
57
    }
58
}
59