Completed
Push — master ( f9ba0c...336b1b )
by Kamil
23:42
created

it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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\Component\Order\Aggregator;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Component\Order\Aggregator\AdjustmentsAggregatorInterface;
16
use Sylius\Component\Order\Model\AdjustmentInterface;
17
18
/**
19
 * @author Mateusz Zalewski <[email protected]>
20
 */
21
class AdjustmentsByLabelAggregatorSpec extends ObjectBehavior
22
{
23
    function it_is_initializable()
24
    {
25
        $this->shouldHaveType('Sylius\Component\Order\Aggregator\AdjustmentsByLabelAggregator');
26
    }
27
28
    function it_implements_adjustments_aggregator_interface()
29
    {
30
        $this->shouldImplement(AdjustmentsAggregatorInterface::class);
31
    }
32
33
    function it_aggregates_given_adjustments_array_by_description(
34
        AdjustmentInterface $adjustment1,
35
        AdjustmentInterface $adjustment2,
36
        AdjustmentInterface $adjustment3,
37
        AdjustmentInterface $adjustment4
38
    ) {
39
        $adjustment1->getDescription()->willReturn('tax 1');
40
        $adjustment1->getAmount()->willReturn(1000);
41
        $adjustment2->getDescription()->willReturn('tax 1');
42
        $adjustment2->getAmount()->willReturn(3000);
43
44
        $adjustment3->getDescription()->willReturn('tax 2');
45
        $adjustment3->getAmount()->willReturn(4000);
46
        $adjustment4->getDescription()->willReturn('tax 2');
47
        $adjustment4->getAmount()->willReturn(-2000);
48
49
        $this->aggregate(array($adjustment1, $adjustment2, $adjustment3, $adjustment4))->shouldReturn(array(
50
            'tax 1' => 4000,
51
            'tax 2' => 2000,
52
        ));
53
    }
54
55
    function it_throws_exception_if_any_array_element_is_not_adjustment(
56
        AdjustmentInterface $adjustment1,
57
        AdjustmentInterface $adjustment2
58
    ) {
59
        $adjustment1->getDescription()->willReturn('tax 1');
60
        $adjustment1->getAmount()->willReturn(1000);
61
        $adjustment2->getDescription()->willReturn('tax 1');
62
        $adjustment2->getAmount()->willReturn(3000);
63
64
        $this
65
            ->shouldThrow(new \InvalidArgumentException('Each adjustments array element must implement '.AdjustmentInterface::class.'.'))
66
            ->during('aggregate', array(array($adjustment1, $adjustment2, 'badObject')))
67
        ;
68
    }
69
}
70