Completed
Push — master ( 60f5be...0d3c0c )
by Kamil
24:02
created

PaymentSpec   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 22
lcom 0
cbo 1
dl 0
loc 136
rs 10
c 1
b 0
f 0

22 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A it_implements_sylius_payment_interface() 0 4 1
A it_has_no_id_by_default() 0 4 1
A it_has_no_payment_method_by_default() 0 4 1
A its_payment_method_is_mutable() 0 5 1
A it_has_no_source_by_default() 0 4 1
A it_allows_to_assign_a_source() 0 5 1
A it_allows_to_remove_a_source() 0 6 1
A it_has_amount_equal_to_0_by_default() 0 4 1
A its_amount_is_mutable() 0 5 1
A its_amount_should_accept_only_integer() 0 10 1
A it_has_new_state_by_default() 0 4 1
A its_state_is_mutable() 0 5 1
A it_initializes_creation_date_by_default() 0 4 1
A its_creation_date_is_mutable() 0 7 1
A it_has_no_last_update_date_by_default() 0 4 1
A its_last_update_date_is_mutable() 0 7 1
A its_details_are_mutable() 0 5 1
A its_details_could_be_set_from_traversable() 0 7 1
A it_throws_exception_if_details_given_are_neither_array_nor_traversable() 0 5 1
A it_has_no_currency_code_by_default() 0 4 1
A its_currency_code_is_mutable() 0 5 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
namespace spec\Sylius\Component\Payment\Model;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Component\Payment\Model\CreditCardInterface;
16
use Sylius\Component\Payment\Model\PaymentInterface;
17
use Sylius\Component\Payment\Model\PaymentMethodInterface;
18
19
/**
20
 * @author Paweł Jędrzejewski <[email protected]>
21
 */
22
class PaymentSpec extends ObjectBehavior
23
{
24
    function it_is_initializable()
25
    {
26
        $this->shouldHaveType('Sylius\Component\Payment\Model\Payment');
27
    }
28
29
    function it_implements_sylius_payment_interface()
30
    {
31
        $this->shouldImplement(PaymentInterface::class);
32
    }
33
34
    function it_has_no_id_by_default()
35
    {
36
        $this->getId()->shouldReturn(null);
37
    }
38
39
    function it_has_no_payment_method_by_default()
40
    {
41
        $this->getMethod()->shouldReturn(null);
42
    }
43
44
    function its_payment_method_is_mutable(PaymentMethodInterface $method)
45
    {
46
        $this->setMethod($method);
47
        $this->getMethod()->shouldReturn($method);
48
    }
49
50
    function it_has_no_source_by_default()
51
    {
52
        $this->getSource()->shouldReturn(null);
53
    }
54
55
    function it_allows_to_assign_a_source(CreditCardInterface $source)
56
    {
57
        $this->setSource($source);
58
        $this->getSource()->shouldReturn($source);
59
    }
60
61
    function it_allows_to_remove_a_source(CreditCardInterface $source)
62
    {
63
        $this->setSource($source);
64
        $this->setSource(null);
65
        $this->getSource()->shouldReturn(null);
66
    }
67
68
    function it_has_no_currency_code_by_default()
69
    {
70
        $this->getCurrencyCode()->shouldReturn(null);
71
    }
72
73
    function its_currency_code_is_mutable()
74
    {
75
        $this->setCurrencyCode('EUR');
76
        $this->getCurrencyCode()->shouldReturn('EUR');
77
    }
78
79
    function it_has_amount_equal_to_0_by_default()
80
    {
81
        $this->getAmount()->shouldReturn(0);
82
    }
83
84
    function its_amount_is_mutable()
85
    {
86
        $this->setAmount(4999);
87
        $this->getAmount()->shouldReturn(4999);
88
    }
89
90
    function its_amount_should_accept_only_integer()
91
    {
92
        $this->setAmount(4498);
93
        $this->getAmount()->shouldBeInteger();
94
        $this->shouldThrow('\InvalidArgumentException')->duringSetAmount(44.98 * 100);
95
        $this->shouldThrow('\InvalidArgumentException')->duringSetAmount('4498');
96
        $this->shouldThrow('\InvalidArgumentException')->duringSetAmount(round(44.98 * 100));
97
        $this->shouldThrow('\InvalidArgumentException')->duringSetAmount([4498]);
98
        $this->shouldThrow('\InvalidArgumentException')->duringSetAmount(new \stdClass());
99
    }
100
101
    function it_has_new_state_by_default()
102
    {
103
        $this->getState()->shouldReturn(PaymentInterface::STATE_NEW);
104
    }
105
106
    function its_state_is_mutable()
107
    {
108
        $this->setState(PaymentInterface::STATE_COMPLETED);
109
        $this->getState()->shouldReturn(PaymentInterface::STATE_COMPLETED);
110
    }
111
112
    function it_initializes_creation_date_by_default()
113
    {
114
        $this->getCreatedAt()->shouldHaveType('DateTime');
115
    }
116
117
    function its_creation_date_is_mutable()
118
    {
119
        $date = new \DateTime('last year');
120
121
        $this->setCreatedAt($date);
122
        $this->getCreatedAt()->shouldReturn($date);
123
    }
124
125
    function it_has_no_last_update_date_by_default()
126
    {
127
        $this->getUpdatedAt()->shouldReturn(null);
128
    }
129
130
    function its_last_update_date_is_mutable()
131
    {
132
        $date = new \DateTime('last year');
133
134
        $this->setUpdatedAt($date);
135
        $this->getUpdatedAt()->shouldReturn($date);
136
    }
137
138
    function its_details_are_mutable()
139
    {
140
        $this->setDetails(['foo', 'bar']);
141
        $this->getDetails()->shouldReturn(['foo', 'bar']);
142
    }
143
144
    function its_details_could_be_set_from_traversable()
145
    {
146
        $details = new \ArrayObject(['foo', 'bar']);
147
148
        $this->setDetails($details);
149
        $this->getDetails()->shouldReturn(['foo', 'bar']);
150
    }
151
152
    function it_throws_exception_if_details_given_are_neither_array_nor_traversable()
153
    {
154
        $this->shouldThrow('Sylius\Component\Resource\Exception\UnexpectedTypeException')
155
            ->duringSetDetails('invalidDetails');
156
    }
157
}
158