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\Bundle\CoreBundle\Taxation\Strategy; |
13
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
15
|
|
|
use Prophecy\Argument; |
16
|
|
|
use Sylius\Bundle\CoreBundle\Taxation\Strategy\TaxCalculationStrategy; |
17
|
|
|
use Sylius\Bundle\SettingsBundle\Model\SettingsInterface; |
18
|
|
|
use Sylius\Component\Addressing\Model\ZoneInterface; |
19
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
20
|
|
|
use Sylius\Component\Core\Taxation\Applicator\OrderTaxesApplicatorInterface; |
21
|
|
|
use Sylius\Component\Core\Taxation\Strategy\AbstractTaxCalculationStrategy; |
22
|
|
|
use Sylius\Component\Core\Taxation\Strategy\TaxCalculationStrategyInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @mixin TaxCalculationStrategy |
26
|
|
|
* |
27
|
|
|
* @author Mark McKelvie <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
class TaxCalculationStrategySpec extends ObjectBehavior |
30
|
|
|
{ |
31
|
|
|
function let( |
32
|
|
|
OrderTaxesApplicatorInterface $applicatorOne, |
33
|
|
|
OrderTaxesApplicatorInterface $applicatorTwo, |
34
|
|
|
SettingsInterface $settings |
35
|
|
|
) { |
36
|
|
|
$this->beConstructedWith('order_items_based', [$applicatorOne, $applicatorTwo], $settings); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_is_initializable() |
40
|
|
|
{ |
41
|
|
|
$this->shouldHaveType('Sylius\Bundle\CoreBundle\Taxation\Strategy\TaxCalculationStrategy'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function it_extends_abstract_tax_calculation_strategy() |
45
|
|
|
{ |
46
|
|
|
$this->shouldHaveType(AbstractTaxCalculationStrategy::class); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function it_implements_a_tax_calculation_strategy_interface() |
50
|
|
|
{ |
51
|
|
|
$this->shouldImplement(TaxCalculationStrategyInterface::class); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
function it_has_a_type() |
55
|
|
|
{ |
56
|
|
|
$this->getType()->shouldReturn('order_items_based'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function it_throws_an_exception_if_any_of_the_applicators_are_not_of_the_correct_type( |
60
|
|
|
OrderTaxesApplicatorInterface $applicatorOne, |
61
|
|
|
OrderTaxesApplicatorInterface $applicatorTwo, |
62
|
|
|
\stdClass $applicatorThree, |
63
|
|
|
SettingsInterface $settings |
64
|
|
|
) { |
65
|
|
|
$this->beConstructedWith('order_items_based', [$applicatorOne, $applicatorTwo, $applicatorThree], $settings); |
66
|
|
|
|
67
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->duringInstantiation(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
function it_can_be_supported_when_the_default_tax_calculation_strategy_setting_matches_the_strategy_type( |
71
|
|
|
SettingsInterface $settings, |
72
|
|
|
OrderInterface $order, |
73
|
|
|
ZoneInterface $zone |
74
|
|
|
) { |
75
|
|
|
$settings->get('default_tax_calculation_strategy')->willReturn('order_items_based'); |
76
|
|
|
|
77
|
|
|
$this->supports($order, $zone)->shouldReturn(true); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
function it_cannot_be_supported_when_the_default_tax_calculation_strategy_setting_does_not_match_the_strategy_type( |
81
|
|
|
SettingsInterface $settings, |
82
|
|
|
OrderInterface $order, |
83
|
|
|
ZoneInterface $zone |
84
|
|
|
) { |
85
|
|
|
$settings->get('default_tax_calculation_strategy')->willReturn('order_item_units_based'); |
86
|
|
|
|
87
|
|
|
$this->supports($order, $zone)->shouldReturn(false); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
function it_applies_all_of_the_applicators( |
91
|
|
|
OrderTaxesApplicatorInterface $applicatorOne, |
92
|
|
|
OrderTaxesApplicatorInterface $applicatorTwo, |
93
|
|
|
OrderInterface $order, |
94
|
|
|
ZoneInterface $zone |
95
|
|
|
) { |
96
|
|
|
$applicatorOne->apply($order, $zone)->shouldBeCalled(); |
97
|
|
|
$applicatorTwo->apply($order, $zone)->shouldBeCalled(); |
98
|
|
|
|
99
|
|
|
$this->applyTaxes($order, $zone); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|