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

TotalOfItemsFromTaxonRuleUpdaterSpec   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_removes_rules_that_using_deleted_taxon() 0 24 1
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 PhpSpec\ObjectBehavior;
17
use Sylius\Component\Core\Model\PromotionInterface;
18
use Sylius\Component\Core\Model\TaxonInterface;
19
use Sylius\Component\Promotion\Model\PromotionRuleInterface;
20
use Sylius\Component\Resource\Repository\RepositoryInterface;
21
22
final class TotalOfItemsFromTaxonRuleUpdaterSpec extends ObjectBehavior
23
{
24
    function let(RepositoryInterface $promotionRuleRepository): void
25
    {
26
        $this->beConstructedWith($promotionRuleRepository);
27
    }
28
29
    function it_removes_rules_that_using_deleted_taxon(
30
        RepositoryInterface $promotionRuleRepository,
31
        PromotionRuleInterface $firstPromotionRule,
32
        PromotionRuleInterface $secondPromotionRule,
33
        PromotionInterface $promotion,
34
        TaxonInterface $taxon
35
    ): void {
36
        $taxon->getCode()->willReturn('toys');
37
38
        $promotionRuleRepository
39
            ->findBy(['type' => 'total_of_items_from_taxon'])
40
            ->willReturn([$firstPromotionRule, $secondPromotionRule])
41
        ;
42
        $firstPromotionRule->getConfiguration()->willReturn(['web' => ['taxon' => 'mugs', 'amount' => 500]]);
43
        $secondPromotionRule->getConfiguration()->willReturn(['web' => ['taxon' => 'toys', 'amount' => 300]]);
44
45
        $secondPromotionRule->getPromotion()->willReturn($promotion);
46
        $promotion->getCode()->willReturn('christmas');
47
48
        $promotionRuleRepository->remove($firstPromotionRule)->shouldNotBeCalled();
49
        $promotionRuleRepository->remove($secondPromotionRule)->shouldBeCalled();
50
51
        $this->updateAfterDeletingTaxon($taxon)->shouldReturn(['christmas']);
52
    }
53
}
54