Completed
Push — scalar-types/user ( 04f6b1...6e06c6 )
by Kamil
57:21 queued 32:30
created

TaxRateResolverSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_implements_tax_rate_resolver_interface() 0 4 1
A it_returns_tax_rate_for_given_taxable_category() 0 11 1
A it_returns_null_if_tax_rate_for_given_taxable_category_does_not_exist() 0 10 1
A it_returns_null_if_taxable_does_not_belong_to_any_category() 0 7 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\Taxation\Resolver;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Component\Resource\Repository\RepositoryInterface;
18
use Sylius\Component\Taxation\Model\TaxableInterface;
19
use Sylius\Component\Taxation\Model\TaxCategoryInterface;
20
use Sylius\Component\Taxation\Model\TaxRateInterface;
21
use Sylius\Component\Taxation\Resolver\TaxRateResolverInterface;
22
23
/**
24
 * @author Paweł Jędrzejewski <[email protected]>
25
 */
26
final class TaxRateResolverSpec extends ObjectBehavior
27
{
28
    function let(RepositoryInterface $taxRateRepository): void
29
    {
30
        $this->beConstructedWith($taxRateRepository);
31
    }
32
33
    function it_implements_tax_rate_resolver_interface(): void
34
    {
35
        $this->shouldImplement(TaxRateResolverInterface::class);
36
    }
37
38
    function it_returns_tax_rate_for_given_taxable_category(
39
        $taxRateRepository,
40
        TaxableInterface $taxable,
41
        TaxCategoryInterface $taxCategory,
42
        TaxRateInterface $taxRate
43
    ): void {
44
        $taxable->getTaxCategory()->willReturn($taxCategory);
45
        $taxRateRepository->findOneBy(['category' => $taxCategory])->shouldBeCalled()->willReturn($taxRate);
46
47
        $this->resolve($taxable)->shouldReturn($taxRate);
48
    }
49
50
    function it_returns_null_if_tax_rate_for_given_taxable_category_does_not_exist(
51
        $taxRateRepository,
52
        TaxableInterface $taxable,
53
        TaxCategoryInterface $taxCategory
54
    ): void {
55
        $taxable->getTaxCategory()->willReturn($taxCategory);
56
        $taxRateRepository->findOneBy(['category' => $taxCategory])->shouldBeCalled()->willReturn(null);
57
58
        $this->resolve($taxable)->shouldReturn(null);
59
    }
60
61
    function it_returns_null_if_taxable_does_not_belong_to_any_category(
62
        TaxableInterface $taxable
63
    ): void {
64
        $taxable->getTaxCategory()->willReturn(null);
65
66
        $this->resolve($taxable)->shouldReturn(null);
67
    }
68
}
69