-
Notifications
You must be signed in to change notification settings - Fork 2
/
PaymentDataTest.php
150 lines (119 loc) · 4.73 KB
/
PaymentDataTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
namespace SwedbankPay\Checkout\Test\Unit;
use Magento\Framework\Exception\NoSuchEntityException;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use SwedbankPay\Checkout\Api\Data\OrderInterface as PaymentOrderInterface;
use SwedbankPay\Checkout\Api\Data\QuoteInterface as PaymentQuoteInterface;
use SwedbankPay\Checkout\Api\OrderRepositoryInterface as PaymentOrderRepository;
use SwedbankPay\Checkout\Api\QuoteRepositoryInterface as PaymentQuoteRepository;
use SwedbankPay\Checkout\Helper\PaymentData;
use SwedbankPay\Core\Logger\Logger;
class PaymentDataTest extends TestCase
{
/**
* @var PaymentData
*/
protected $paymentData;
/**
* @var PaymentOrderRepository|MockObject
*/
protected $paymentOrderRepo;
/**
* @var PaymentQuoteRepository|MockObject
*/
protected $paymentQuoteRepo;
/**
* @var Logger|MockObject
*/
protected $logger;
public function setUp()
{
$this->paymentOrderRepo = $this->getMockBuilder(PaymentOrderRepository::class)
->disableOriginalConstructor()
->getMock();
$this->paymentQuoteRepo = $this->getMockBuilder(PaymentQuoteRepository::class)
->disableOriginalConstructor()
->getMock();
$this->logger = $this->getMockBuilder(Logger::class)
->disableOriginalConstructor()
->getMock();
$this->paymentData = new PaymentData(
$this->paymentOrderRepo,
$this->paymentQuoteRepo,
$this->logger
);
}
/**
* @throws NoSuchEntityException
*/
public function testGetByPaymentOrderIdThrowsException()
{
$paymentOrderId = "5adc265f-f87f-4313-577e-08d3dca1a26c";
$this->paymentOrderRepo->method('getByPaymentOrderId')->willThrowException(new NoSuchEntityException());
$this->paymentQuoteRepo->method('getByPaymentOrderId')->willThrowException(new NoSuchEntityException());
$this->expectException(NoSuchEntityException::class);
$this->expectExceptionMessage(
sprintf("Unable to find a SwedbankPay payment matching Payment Order ID:\n%s", $paymentOrderId)
);
$this->paymentData->getByPaymentOrderId($paymentOrderId);
}
/**
* @throws NoSuchEntityException
*/
public function testGetByPaymentOrderIdReturnsOrderInstance()
{
$paymentOrderId = "5adc265f-f87f-4313-577e-08d3dca1a26c";
$order = $this->createMock(PaymentOrderInterface::class);
$this->paymentOrderRepo->method('getByPaymentOrderId')->will($this->returnValue($order));
$this->paymentQuoteRepo->method('getByPaymentOrderId')->willThrowException(new NoSuchEntityException());
$this->assertInstanceOf(
PaymentOrderInterface::class,
$this->paymentData->getByPaymentOrderId($paymentOrderId)
);
$this->assertNotInstanceOf(
PaymentQuoteInterface::class,
$this->paymentData->getByPaymentOrderId($paymentOrderId)
);
}
/**
* @throws NoSuchEntityException
*/
public function testGetByPaymentOrderIdReturnsQuoteInstance()
{
$paymentOrderId = "5adc265f-f87f-4313-577e-08d3dca1a26c";
$quote = $this->createMock(PaymentQuoteInterface::class);
$this->paymentOrderRepo->method('getByPaymentOrderId')->willThrowException(new NoSuchEntityException());
$this->paymentQuoteRepo->method('getByPaymentOrderId')->will($this->returnValue($quote));
$this->assertNotInstanceOf(
PaymentOrderInterface::class,
$this->paymentData->getByPaymentOrderId($paymentOrderId)
);
$this->assertInstanceOf(
PaymentQuoteInterface::class,
$this->paymentData->getByPaymentOrderId($paymentOrderId)
);
}
/**
* @throws NoSuchEntityException
*/
public function testGetByOrderThrowsException()
{
$order = $this->createMock(PaymentOrderInterface::class);
$this->paymentOrderRepo->method('getByOrderId')->will($this->returnValue($order));
$this->expectException(NoSuchEntityException::class);
$this->paymentData->getByOrder(null);
}
/**
* @throws NoSuchEntityException
*/
public function testGetByOrderWithOrderIdReturnsOrder()
{
$orderId = 100;
$order = $this->createMock(PaymentOrderInterface::class);
$order->method('getId')->will($this->returnValue($orderId));
$this->paymentOrderRepo->method('getByOrderId')->will($this->returnValue($order));
$this->assertInstanceOf(PaymentOrderInterface::class, $this->paymentData->getByOrder($orderId));
$this->assertEquals($orderId, $this->paymentData->getByOrder($orderId)->getId());
}
}