1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainAltapayBundle\Tests\PayloadGenerator; |
4
|
|
|
|
5
|
|
|
use Loevgaard\AltaPay\Payload\OrderLine as OrderLinePayload; |
6
|
|
|
use Loevgaard\AltaPay\Payload\PaymentRequest\Config as ConfigPayload; |
7
|
|
|
use Loevgaard\AltaPay\Payload\PaymentRequest\CustomerInfo as CustomerInfoPayload; |
8
|
|
|
use Loevgaard\Dandomain\Pay\Handler; |
9
|
|
|
use Loevgaard\Dandomain\Pay\PaymentRequest as DandomainPaymentRequest; |
10
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\Payment; |
11
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\TerminalInterface; |
12
|
|
|
use Loevgaard\DandomainAltapayBundle\Tests\PayloadGenerator\Fixture\Gateway; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
16
|
|
|
|
17
|
|
|
final class PaymentRequestPayloadGeneratorTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
public function testCreateOrderLine() |
20
|
|
|
{ |
21
|
|
|
$generator = $this->getGenerator(); |
22
|
|
|
|
23
|
|
|
$description = 'description'; |
24
|
|
|
$itemId = 'itemid'; |
25
|
|
|
$quantity = 1.0; |
26
|
|
|
$unitPrice = 99.95; |
27
|
|
|
|
28
|
|
|
// without optional parameters |
29
|
|
|
$payload = $generator->createOrderLine($description, $itemId, $quantity, $unitPrice); |
30
|
|
|
$this->assertInstanceOf(OrderLinePayload::class, $payload); |
31
|
|
|
$this->assertSame($description, $payload->getDescription()); |
32
|
|
|
$this->assertSame($itemId, $payload->getItemId()); |
33
|
|
|
$this->assertSame($quantity, $payload->getQuantity()); |
34
|
|
|
$this->assertSame($unitPrice, $payload->getUnitPrice()); |
35
|
|
|
|
36
|
|
|
// with tax percent |
37
|
|
|
$taxPercent = 25.0; |
38
|
|
|
$payload = $generator->createOrderLine($description, $itemId, $quantity, $unitPrice, $taxPercent); |
39
|
|
|
$this->assertInstanceOf(OrderLinePayload::class, $payload); |
40
|
|
|
$this->assertSame($description, $payload->getDescription()); |
41
|
|
|
$this->assertSame($itemId, $payload->getItemId()); |
42
|
|
|
$this->assertSame($quantity, $payload->getQuantity()); |
43
|
|
|
$this->assertSame($unitPrice, $payload->getUnitPrice()); |
44
|
|
|
$this->assertSame($taxPercent, $payload->getTaxPercent()); |
45
|
|
|
|
46
|
|
|
// with goods type |
47
|
|
|
$goodsType = OrderLinePayload::GOODS_TYPE_ITEM; |
48
|
|
|
$payload = $generator->createOrderLine($description, $itemId, $quantity, $unitPrice, null, $goodsType); |
49
|
|
|
$this->assertInstanceOf(OrderLinePayload::class, $payload); |
50
|
|
|
$this->assertSame($description, $payload->getDescription()); |
51
|
|
|
$this->assertSame($itemId, $payload->getItemId()); |
52
|
|
|
$this->assertSame($quantity, $payload->getQuantity()); |
53
|
|
|
$this->assertSame($unitPrice, $payload->getUnitPrice()); |
54
|
|
|
$this->assertSame($goodsType, $payload->getGoodsType()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testCreateCustomerInfo() |
58
|
|
|
{ |
59
|
|
|
$generator = $this->getGenerator(); |
60
|
|
|
|
61
|
|
|
$billingFirstName = 'billingfirstname'; |
62
|
|
|
$billingLastName = 'billinglastname'; |
63
|
|
|
$billingAddress = 'billingaddress'; |
64
|
|
|
$billingPostal = 'billingpostal'; |
65
|
|
|
$billingCity = 'billingcity'; |
66
|
|
|
$billingCountry = 'billingcountry'; |
67
|
|
|
$shippingFirstName = 'shippingfirstname'; |
68
|
|
|
$shippingLastName = 'shippinglastname'; |
69
|
|
|
$shippingAddress = 'shippingaddress'; |
70
|
|
|
$shippingPostal = 'shippingpostal'; |
71
|
|
|
$shippingCity = 'shippingcity'; |
72
|
|
|
$shippingCountry = 'shippingcountry'; |
73
|
|
|
|
74
|
|
|
// without optional parameters |
75
|
|
|
$payload = $generator->createCustomerInfo($billingFirstName, $billingLastName, $billingAddress, $billingPostal, $billingCity, $billingCountry, $shippingFirstName, $shippingLastName, $shippingAddress, $shippingPostal, $shippingCity, $shippingCountry); |
76
|
|
|
$this->assertInstanceOf(CustomerInfoPayload::class, $payload); |
77
|
|
|
$this->assertSame($billingFirstName, $payload->getBillingFirstName()); |
78
|
|
|
$this->assertSame($billingLastName, $payload->getBillingLastName()); |
79
|
|
|
$this->assertSame($billingAddress, $payload->getBillingAddress()); |
80
|
|
|
$this->assertSame($billingPostal, $payload->getBillingPostal()); |
81
|
|
|
$this->assertSame($billingCity, $payload->getBillingCity()); |
82
|
|
|
$this->assertSame($billingCountry, $payload->getBillingCountry()); |
83
|
|
|
$this->assertSame($shippingFirstName, $payload->getShippingFirstName()); |
84
|
|
|
$this->assertSame($shippingLastName, $payload->getShippingLastName()); |
85
|
|
|
$this->assertSame($shippingAddress, $payload->getShippingAddress()); |
86
|
|
|
$this->assertSame($shippingPostal, $payload->getShippingPostal()); |
87
|
|
|
$this->assertSame($shippingCity, $payload->getShippingCity()); |
88
|
|
|
$this->assertSame($shippingCountry, $payload->getShippingCountry()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testCreateConfig() |
92
|
|
|
{ |
93
|
|
|
$generator = $this->getGenerator(); |
94
|
|
|
|
95
|
|
|
$callbackForm = 'form'; |
96
|
|
|
$callbackOk = 'ok'; |
97
|
|
|
$callbackFail = 'fail'; |
98
|
|
|
$callbackRedirect = 'redirect'; |
99
|
|
|
$callbackOpen = 'open'; |
100
|
|
|
$callbackNotification = 'notification'; |
101
|
|
|
|
102
|
|
|
// without optional parameters |
103
|
|
|
$payload = $generator->createConfig($callbackForm, $callbackOk, $callbackFail, $callbackRedirect, $callbackOpen, $callbackNotification); |
104
|
|
|
$this->assertInstanceOf(ConfigPayload::class, $payload); |
105
|
|
|
$this->assertSame($callbackForm, $payload->getCallbackForm()); |
106
|
|
|
$this->assertSame($callbackOk, $payload->getCallbackOk()); |
107
|
|
|
$this->assertSame($callbackFail, $payload->getCallbackFail()); |
108
|
|
|
$this->assertSame($callbackRedirect, $payload->getCallbackRedirect()); |
109
|
|
|
$this->assertSame($callbackOpen, $payload->getCallbackOpen()); |
110
|
|
|
$this->assertSame($callbackNotification, $payload->getCallbackNotification()); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
private function getGenerator() |
114
|
|
|
{ |
115
|
|
|
$container = $this->getContainer(); |
116
|
|
|
$paymentRequest = $this->getPaymentRequest(); |
117
|
|
|
$terminal = $this->getTerminal(); |
118
|
|
|
$payment = $this->getPayment(); |
119
|
|
|
$handler = $this->getHandler(); |
120
|
|
|
|
121
|
|
|
$generator = new Gateway($container, $paymentRequest, $terminal, $payment, $handler); |
|
|
|
|
122
|
|
|
|
123
|
|
|
return $generator; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ContainerInterface |
128
|
|
|
*/ |
129
|
|
|
private function getContainer() |
130
|
|
|
{ |
131
|
|
|
$container = $this->getMockForAbstractClass(ContainerInterface::class); |
132
|
|
|
|
133
|
|
|
return $container; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
private function getPaymentRequest() |
137
|
|
|
{ |
138
|
|
|
$paymentRequest = new DandomainPaymentRequest(); |
139
|
|
|
|
140
|
|
|
return $paymentRequest; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return TerminalInterface|\PHPUnit_Framework_MockObject_MockObject |
145
|
|
|
*/ |
146
|
|
|
private function getTerminal() |
147
|
|
|
{ |
148
|
|
|
$terminal = $this->getMockForAbstractClass(TerminalInterface::class); |
149
|
|
|
|
150
|
|
|
return $terminal; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return Payment|\PHPUnit_Framework_MockObject_MockObject |
155
|
|
|
*/ |
156
|
|
|
private function getPayment() |
157
|
|
|
{ |
158
|
|
|
$payment = $this->getMockForAbstractClass(Payment::class); |
159
|
|
|
|
160
|
|
|
return $payment; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
private function getHandler() |
164
|
|
|
{ |
165
|
|
|
$request = $this->getMockForAbstractClass(ServerRequestInterface::class); |
166
|
|
|
$handler = new Handler($request, 'sharedkey1', 'sharedkey2'); |
167
|
|
|
|
168
|
|
|
return $handler; |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.