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\OrderBundle\Twig; |
13
|
|
|
|
14
|
|
|
use PhpSpec\Exception\Example\FailureException; |
15
|
|
|
use PhpSpec\ObjectBehavior; |
16
|
|
|
use Prophecy\Argument; |
17
|
|
|
use Sylius\Bundle\OrderBundle\Aggregator\AdjustmentsAggregatorInterface; |
18
|
|
|
use Sylius\Bundle\OrderBundle\Templating\Helper\AdjustmentsHelper; |
19
|
|
|
use Sylius\Component\Order\Model\AdjustmentInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Mateusz Zalewski <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class AggregateAdjustmentsExtensionSpec extends ObjectBehavior |
25
|
|
|
{ |
26
|
|
|
function let(AdjustmentsHelper $adjustmentsHelper) |
27
|
|
|
{ |
28
|
|
|
$this->beConstructedWith($adjustmentsHelper); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
function it_is_initializable() |
32
|
|
|
{ |
33
|
|
|
$this->shouldHaveType('Sylius\Bundle\OrderBundle\Twig\AggregateAdjustmentsExtension'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function it_is_twig_extension() |
37
|
|
|
{ |
38
|
|
|
$this->shouldHaveType(\Twig_Extension::class); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
function it_has_functions() |
42
|
|
|
{ |
43
|
|
|
$this->getFunctions()->shouldHaveFunction(new \Twig_SimpleFunction('sylius_aggregate_adjustments', array($this, 'aggregateAdjustments'))); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
function it_uses_helper_to_get_aggregated_adjustments( |
47
|
|
|
$adjustmentsHelper, |
48
|
|
|
AdjustmentInterface $adjustment1, |
49
|
|
|
AdjustmentInterface $adjustment2, |
50
|
|
|
AdjustmentInterface $adjustment3 |
51
|
|
|
) { |
52
|
|
|
$adjustmentsHelper |
53
|
|
|
->getAggregatedAdjustments(array($adjustment1, $adjustment2, $adjustment3)) |
54
|
|
|
->willReturn(array('tax 1' => 1000, 'tax2' => 500)) |
55
|
|
|
; |
56
|
|
|
|
57
|
|
|
$this->aggregateAdjustments(array($adjustment1, $adjustment2, $adjustment3))->shouldReturn(array('tax 1' => 1000, 'tax2' => 500)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
function it_has_name() |
61
|
|
|
{ |
62
|
|
|
$this->getName()->shouldReturn('sylius_aggregate_adjustments'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getMatchers() |
66
|
|
|
{ |
67
|
|
|
return [ |
68
|
|
|
'haveFunction' => function ($subject, $key) { |
69
|
|
|
|
70
|
|
|
if (!is_array($subject)) { |
71
|
|
|
throw new FailureException('Subject of "hasFunction" matcher must be an array'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if (!$key instanceof \Twig_SimpleFunction) { |
75
|
|
|
throw new FailureException('Key of "hasFunction" matcher must be \Twig_SimpleFunction object'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** @var \Twig_SimpleFunction $subjectElement */ |
79
|
|
|
foreach ($subject as $subjectElement) { |
80
|
|
|
if ($subjectElement->getName() === $key->getName() && $subjectElement->getCallable()[1] === $key->getCallable()[1]) { |
81
|
|
|
return true; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return false; |
86
|
|
|
} |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|