Completed
Push — master ( 04583c...efa664 )
by Joachim
18:49
created

getDandomainPayment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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\Helper\ChecksumHelper;
9
use Loevgaard\Dandomain\Pay\Model\Payment as DandomainPayment;
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 Symfony\Component\DependencyInjection\ContainerInterface;
15
16
final class PaymentRequestPayloadGeneratorTest extends TestCase
17
{
18
    public function testCreateOrderLine()
19
    {
20
        $generator = $this->getGenerator();
21
22
        $description = 'description';
23
        $itemId = 'itemid';
24
        $quantity = 1.0;
25
        $unitPrice = 99.95;
26
27
        // without optional parameters
28
        $payload = $generator->createOrderLine($description, $itemId, $quantity, $unitPrice);
29
        $this->assertInstanceOf(OrderLinePayload::class, $payload);
30
        $this->assertSame($description, $payload->getDescription());
31
        $this->assertSame($itemId, $payload->getItemId());
32
        $this->assertSame($quantity, $payload->getQuantity());
33
        $this->assertSame($unitPrice, $payload->getUnitPrice());
34
35
        // with tax percent
36
        $taxPercent = 25.0;
37
        $payload = $generator->createOrderLine($description, $itemId, $quantity, $unitPrice, $taxPercent);
38
        $this->assertInstanceOf(OrderLinePayload::class, $payload);
39
        $this->assertSame($description, $payload->getDescription());
40
        $this->assertSame($itemId, $payload->getItemId());
41
        $this->assertSame($quantity, $payload->getQuantity());
42
        $this->assertSame($unitPrice, $payload->getUnitPrice());
43
        $this->assertSame($taxPercent, $payload->getTaxPercent());
44
45
        // with goods type
46
        $goodsType = OrderLinePayload::GOODS_TYPE_ITEM;
47
        $payload = $generator->createOrderLine($description, $itemId, $quantity, $unitPrice, null, $goodsType);
48
        $this->assertInstanceOf(OrderLinePayload::class, $payload);
49
        $this->assertSame($description, $payload->getDescription());
50
        $this->assertSame($itemId, $payload->getItemId());
51
        $this->assertSame($quantity, $payload->getQuantity());
52
        $this->assertSame($unitPrice, $payload->getUnitPrice());
53
        $this->assertSame($goodsType, $payload->getGoodsType());
54
    }
55
56
    public function testCreateCustomerInfo()
57
    {
58
        $generator = $this->getGenerator();
59
60
        $billingFirstName = 'billingfirstname';
61
        $billingLastName = 'billinglastname';
62
        $billingAddress = 'billingaddress';
63
        $billingPostal = 'billingpostal';
64
        $billingCity = 'billingcity';
65
        $billingCountry = 'billingcountry';
66
        $shippingFirstName = 'shippingfirstname';
67
        $shippingLastName = 'shippinglastname';
68
        $shippingAddress = 'shippingaddress';
69
        $shippingPostal = 'shippingpostal';
70
        $shippingCity = 'shippingcity';
71
        $shippingCountry = 'shippingcountry';
72
73
        // without optional parameters
74
        $payload = $generator->createCustomerInfo($billingFirstName, $billingLastName, $billingAddress, $billingPostal, $billingCity, $billingCountry, $shippingFirstName, $shippingLastName, $shippingAddress, $shippingPostal, $shippingCity, $shippingCountry);
75
        $this->assertInstanceOf(CustomerInfoPayload::class, $payload);
76
        $this->assertSame($billingFirstName, $payload->getBillingFirstName());
77
        $this->assertSame($billingLastName, $payload->getBillingLastName());
78
        $this->assertSame($billingAddress, $payload->getBillingAddress());
79
        $this->assertSame($billingPostal, $payload->getBillingPostal());
80
        $this->assertSame($billingCity, $payload->getBillingCity());
81
        $this->assertSame($billingCountry, $payload->getBillingCountry());
82
        $this->assertSame($shippingFirstName, $payload->getShippingFirstName());
83
        $this->assertSame($shippingLastName, $payload->getShippingLastName());
84
        $this->assertSame($shippingAddress, $payload->getShippingAddress());
85
        $this->assertSame($shippingPostal, $payload->getShippingPostal());
86
        $this->assertSame($shippingCity, $payload->getShippingCity());
87
        $this->assertSame($shippingCountry, $payload->getShippingCountry());
88
    }
89
90
    public function testCreateConfig()
91
    {
92
        $generator = $this->getGenerator();
93
94
        $callbackForm = 'form';
95
        $callbackOk = 'ok';
96
        $callbackFail = 'fail';
97
        $callbackRedirect = 'redirect';
98
        $callbackOpen = 'open';
99
        $callbackNotification = 'notification';
100
101
        // without optional parameters
102
        $payload = $generator->createConfig($callbackForm, $callbackOk, $callbackFail, $callbackRedirect, $callbackOpen, $callbackNotification);
103
        $this->assertInstanceOf(ConfigPayload::class, $payload);
104
        $this->assertSame($callbackForm, $payload->getCallbackForm());
105
        $this->assertSame($callbackOk, $payload->getCallbackOk());
106
        $this->assertSame($callbackFail, $payload->getCallbackFail());
107
        $this->assertSame($callbackRedirect, $payload->getCallbackRedirect());
108
        $this->assertSame($callbackOpen, $payload->getCallbackOpen());
109
        $this->assertSame($callbackNotification, $payload->getCallbackNotification());
110
    }
111
112
    private function getGenerator()
113
    {
114
        $container = $this->getContainer();
115
        $dandomainPayment = $this->getDandomainPayment();
116
        $terminal = $this->getTerminal();
117
        $payment = $this->getPayment();
118
        $handler = $this->getChecksumHelper($dandomainPayment);
119
120
        $generator = new Gateway($container, $dandomainPayment, $terminal, $payment, $handler);
0 ignored issues
show
Bug introduced by
It seems like $container defined by $this->getContainer() on line 114 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Loevgaard\DandomainAltap...enerator::__construct() does only seem to accept object<Symfony\Component...ion\ContainerInterface>, maybe add an additional type check?

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:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $terminal defined by $this->getTerminal() on line 116 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Loevgaard\DandomainAltap...enerator::__construct() does only seem to accept object<Loevgaard\Dandoma...tity\TerminalInterface>, maybe add an additional type check?

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:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $payment defined by $this->getPayment() on line 117 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Loevgaard\DandomainAltap...enerator::__construct() does only seem to accept object<Loevgaard\Dandoma...yBundle\Entity\Payment>, maybe add an additional type check?

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:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
121
122
        return $generator;
123
    }
124
125
    /**
126
     * @return \PHPUnit_Framework_MockObject_MockObject|ContainerInterface
127
     */
128
    private function getContainer()
129
    {
130
        $container = $this->getMockForAbstractClass(ContainerInterface::class);
131
132
        return $container;
133
    }
134
135
    private function getDandomainPayment()
136
    {
137
        $paymentRequest = new DandomainPayment();
138
139
        return $paymentRequest;
140
    }
141
142
    /**
143
     * @return TerminalInterface|\PHPUnit_Framework_MockObject_MockObject
144
     */
145
    private function getTerminal()
146
    {
147
        $terminal = $this->getMockForAbstractClass(TerminalInterface::class);
148
149
        return $terminal;
150
    }
151
152
    /**
153
     * @return Payment|\PHPUnit_Framework_MockObject_MockObject
154
     */
155
    private function getPayment()
156
    {
157
        $payment = $this->getMockForAbstractClass(Payment::class);
158
159
        return $payment;
160
    }
161
162
    private function getChecksumHelper(DandomainPayment $payment)
163
    {
164
        $checksumHelper = new ChecksumHelper($payment, 'sharedkey1', 'sharedkey2');
165
166
        return $checksumHelper;
167
    }
168
}
169