Completed
Push — master ( f019ba...e16295 )
by Joachim
03:16
created

PaymentTest::testIsRefundable3()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Loevgaard\DandomainAltapayBundle\Tests\Entity;
4
5
use Loevgaard\DandomainAltapayBundle\Entity\Payment;
6
use Loevgaard\Dandomain\Pay\Model\Payment as DandomainPayment;
7
use Loevgaard\Dandomain\Pay\Model\PaymentLine as DandomainPaymentLine;
8
use Loevgaard\DandomainAltapayBundle\Entity\PaymentLine;
9
use PHPUnit\Framework\TestCase;
10
11
class PaymentTest extends TestCase
12
{
13
    public function testGettersSetters()
14
    {
15
        $payment = new Payment();
16
17
        $created = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2017-10-01 04:00:00');
18
        $updated = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2017-10-01 04:00:01');
19
20
        $payment
21
            ->setId(1)
22
            ->setAltapayId('altapayid')
23
            ->setCardStatus('cardstatus')
24
            ->setCreditCardToken('cctoken')
25
            ->setCreditCardMaskedPan('ccmaskedpan')
26
            ->setThreeDSecureResult('3dres')
27
            ->setLiableForChargeback('liable')
28
            ->setBlacklistToken('blacklisttoken')
29
            ->setShop('shop')
30
            ->setTerminal('terminal')
31
            ->setTransactionStatus('transactionstatus')
32
            ->setReasonCode('reasoncode')
33
            ->setMerchantCurrency(208)
34
            ->setMerchantCurrencyAlpha('DKK')
35
            ->setCardHolderCurrency(700)
36
            ->setCardHolderCurrencyAlpha('EUR')
37
            ->setReservedAmount(250.5)
38
            ->setCapturedAmount(125.5)
39
            ->setRefundedAmount(300.4)
40
            ->setRecurringDefaultAmount(400.9)
41
            ->setCreatedDate($created)
42
            ->setUpdatedDate($updated)
43
            ->setPaymentNature('paymentnature')
44
            ->setSupportsRefunds(false)
45
            ->setSupportsRelease(false)
46
            ->setSupportsMultipleCaptures(true)
47
            ->setSupportsMultipleRefunds(true)
48
            ->setFraudRiskScore(13.37)
49
            ->setFraudExplanation('fraudexplanation')
50
        ;
51
52
        $this->assertSame(1, $payment->getId());
53
        $this->assertSame('altapayid', $payment->getAltapayId());
54
        $this->assertSame('cardstatus', $payment->getCardStatus());
55
        $this->assertSame('cctoken', $payment->getCreditCardToken());
56
        $this->assertSame('ccmaskedpan', $payment->getCreditCardMaskedPan());
57
        $this->assertSame('3dres', $payment->getThreeDSecureResult());
58
        $this->assertSame('liable', $payment->getLiableForChargeback());
59
        $this->assertSame('blacklisttoken', $payment->getBlacklistToken());
60
        $this->assertSame('shop', $payment->getShop());
61
        $this->assertSame('terminal', $payment->getTerminal());
62
        $this->assertSame('transactionstatus', $payment->getTransactionStatus());
63
        $this->assertSame('reasoncode', $payment->getReasonCode());
64
        $this->assertSame(208, $payment->getMerchantCurrency());
65
        $this->assertSame('DKK', $payment->getMerchantCurrencyAlpha());
66
        $this->assertSame(700, $payment->getCardHolderCurrency());
67
        $this->assertSame('EUR', $payment->getCardHolderCurrencyAlpha());
68
        $this->assertSame(250.5, $payment->getReservedAmount());
69
        $this->assertSame(125.5, $payment->getCapturedAmount());
70
        $this->assertSame(300.4, $payment->getRefundedAmount());
71
        $this->assertSame(400.9, $payment->getRecurringDefaultAmount());
72
        $this->assertSame($created, $payment->getCreatedDate());
73
        $this->assertSame($updated, $payment->getUpdatedDate());
74
        $this->assertSame('paymentnature', $payment->getPaymentNature());
75
        $this->assertSame(false, $payment->getSupportsRefunds());
76
        $this->assertSame(false, $payment->getSupportsRelease());
77
        $this->assertSame(true, $payment->getSupportsMultipleCaptures());
78
        $this->assertSame(true, $payment->getSupportsMultipleRefunds());
79
        $this->assertSame(13.37, $payment->getFraudRiskScore());
80
        $this->assertSame('fraudexplanation', $payment->getFraudExplanation());
81
    }
82
83
    public function testCreateFromDandomainPayment()
84
    {
85
        // @todo set properties to test that they are transferred correctly
86
        $payment = new Payment();
87
        $payment->setShippingMethod('shippingmethod');
88
        $payment->addPaymentLine(new PaymentLine());
89
90
        $dandomainPayment = new DandomainPayment();
91
        $dandomainPayment->setShippingMethod('shippingmethod');
92
        $dandomainPayment->addPaymentLine(new DandomainPaymentLine());
93
94
        $paymentFromDandomainPayment = Payment::createFromDandomainPayment($dandomainPayment);
95
96
        $this->assertEquals($payment, $paymentFromDandomainPayment);
97
    }
98
99 View Code Duplication
    public function testIsCaptureable1()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
    {
101
        $payment = new Payment();
102
103
        $payment
104
            ->setReservedAmount(100)
105
            ->setCapturedAmount(100)
106
            ->setRefundedAmount(0)
107
        ;
108
109
        $this->assertSame(false, $payment->isCaptureable());
110
    }
111
112 View Code Duplication
    public function testIsCaptureable2()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
113
    {
114
        $payment = new Payment();
115
116
        $payment
117
            ->setReservedAmount(100)
118
            ->setCapturedAmount(10)
119
            ->setRefundedAmount(0)
120
            ->setSupportsMultipleCaptures(false)
121
        ;
122
123
        $this->assertSame(false, $payment->isCaptureable());
124
    }
125
126 View Code Duplication
    public function testIsCaptureable3()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
127
    {
128
        $payment = new Payment();
129
130
        $payment
131
            ->setReservedAmount(100)
132
            ->setCapturedAmount(0)
133
            ->setRefundedAmount(0)
134
        ;
135
136
        $this->assertSame(true, $payment->isCaptureable());
137
    }
138
139
    public function testIsRefundable1()
140
    {
141
        $payment = new Payment();
142
143
        $payment
144
            ->setCapturedAmount(100)
145
            ->setRefundedAmount(100)
146
        ;
147
148
        $this->assertSame(false, $payment->isRefundable());
149
    }
150
151
    public function testIsRefundable2()
152
    {
153
        $payment = new Payment();
154
155
        $payment
156
            ->setCapturedAmount(100)
157
            ->setRefundedAmount(50)
158
            ->setSupportsMultipleRefunds(false)
159
        ;
160
161
        $this->assertSame(false, $payment->isRefundable());
162
    }
163
164
    public function testIsRefundable3()
165
    {
166
        $payment = new Payment();
167
168
        $payment
169
            ->setCapturedAmount(100)
170
            ->setRefundedAmount(0)
171
        ;
172
173
        $this->assertSame(true, $payment->isRefundable());
174
    }
175
}
176