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
|
|
|
namespace spec\Sylius\Behat\Context\Setup; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
15
|
|
|
use PhpSpec\ObjectBehavior; |
16
|
|
|
use Sylius\Component\Addressing\Model\ZoneInterface; |
17
|
|
|
use Sylius\Component\Core\Model\TaxRateInterface; |
18
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
19
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
20
|
|
|
use Sylius\Component\Taxation\Model\TaxCategoryInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author Mateusz Zalewski <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class TaxContextSpec extends ObjectBehavior |
26
|
|
|
{ |
27
|
|
|
function let( |
28
|
|
|
FactoryInterface $taxRateFactory, |
29
|
|
|
FactoryInterface $taxCategoryFactory, |
30
|
|
|
RepositoryInterface $taxRateRepository, |
31
|
|
|
RepositoryInterface $taxCategoryRepository, |
32
|
|
|
RepositoryInterface $zoneRepository |
33
|
|
|
) { |
34
|
|
|
$this->beConstructedWith( |
35
|
|
|
$taxRateFactory, |
36
|
|
|
$taxCategoryFactory, |
37
|
|
|
$taxRateRepository, |
38
|
|
|
$taxCategoryRepository, |
39
|
|
|
$zoneRepository |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function it_is_initializable() |
44
|
|
|
{ |
45
|
|
|
$this->shouldHaveType('Sylius\Behat\Context\Setup\TaxContext'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
function it_implements_context_interface() |
49
|
|
|
{ |
50
|
|
|
$this->shouldImplement(Context::class); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
function it_creates_tax_rate_for_given_tax_category_and_zone( |
54
|
|
|
$taxRateFactory, |
55
|
|
|
$taxCategoryFactory, |
56
|
|
|
$taxRateRepository, |
57
|
|
|
$taxCategoryRepository, |
58
|
|
|
$zoneRepository, |
59
|
|
|
TaxCategoryInterface $taxCategory, |
60
|
|
|
TaxRateInterface $taxRate, |
61
|
|
|
ZoneInterface $zone |
62
|
|
|
) { |
63
|
|
|
$zoneRepository->findOneBy(['code' => 'EU'])->willReturn($zone); |
64
|
|
|
|
65
|
|
|
$taxCategoryFactory->createNew()->willReturn($taxCategory); |
66
|
|
|
$taxCategory->setName('Clothes')->shouldBeCalled(); |
67
|
|
|
$taxCategory->setCode('clothes')->shouldBeCalled(); |
68
|
|
|
|
69
|
|
|
$taxCategoryRepository->add($taxCategory)->shouldBeCalled(); |
70
|
|
|
|
71
|
|
|
$taxRateFactory->createNew()->willReturn($taxRate); |
72
|
|
|
$taxRate->setName('EU VAT')->shouldBeCalled(); |
73
|
|
|
$taxRate->setCode('eu_vat')->shouldBeCalled(); |
74
|
|
|
$taxRate->setAmount(0.23)->shouldBeCalled(); |
75
|
|
|
$taxRate->setCategory($taxCategory)->shouldBeCalled(); |
76
|
|
|
$taxRate->setZone($zone)->shouldBeCalled(); |
77
|
|
|
$taxRate->setCalculator('default')->shouldBeCalled(); |
78
|
|
|
|
79
|
|
|
$taxRateRepository->add($taxRate)->shouldBeCalled(); |
80
|
|
|
|
81
|
|
|
$this->storeHasTaxRateWithinZone('EU VAT', '23%', 'Clothes', $zone); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
function it_casts_tax_category_name_to_tax_category($taxCategoryRepository, TaxCategoryInterface $taxCategory) |
85
|
|
|
{ |
86
|
|
|
$taxCategoryRepository->findOneBy(['name' => 'TaxCategory'])->willReturn($taxCategory); |
87
|
|
|
|
88
|
|
|
$this->castTaxCategoryNameToTaxCategory('TaxCategory')->shouldReturn($taxCategory); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
function it_throws_exception_if_there_is_no_tax_category_with_name_given_to_casting($taxCategoryRepository) |
92
|
|
|
{ |
93
|
|
|
$taxCategoryRepository->findOneBy(['name' => 'TaxCategory'])->willReturn(null); |
94
|
|
|
|
95
|
|
|
$this |
96
|
|
|
->shouldThrow(new \Exception('Tax category with name "TaxCategory" does not exist')) |
97
|
|
|
->during('castTaxCategoryNameToTaxCategory', ['TaxCategory']) |
98
|
|
|
; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|