Skip to content

Commit f7f9b8b

Browse files
authored
Merge pull request #121 from swlodarski-sumoheavy/10.1.x
SP-1172 - Add tests to Magento module pipeline
2 parents 7ef0ee0 + eb4c9b2 commit f7f9b8b

File tree

4 files changed

+73
-7
lines changed

4 files changed

+73
-7
lines changed

.github/workflows/test.yml

+44-3
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,58 @@ on: [push, pull_request]
44

55
env:
66
NODE_VERSION: 18
7+
MODULE_NAME: Bitpay_BPCheckout
8+
COMPOSER_NAME: "bitpay/module-bpcheckout"
79

810
jobs:
11+
unit-tests-81:
12+
name: Unit Tests (PHP 8.1)
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
MAGENTO_VERSION: ["2.4.4", "2.4.5", "2.4.6"]
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: extdn/github-actions-m2/magento-unit-tests/8.1@master
21+
env:
22+
MAGENTO_VERSION: ${{ matrix.MAGENTO_VERSION }}
23+
24+
unit-tests-82:
25+
name: Unit Tests (PHP 8.2)
26+
runs-on: ubuntu-latest
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
MAGENTO_VERSION: ["2.4.6", "2.4.7"]
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: extdn/github-actions-m2/magento-unit-tests/8.2@master
34+
env:
35+
MAGENTO_VERSION: ${{ matrix.MAGENTO_VERSION }}
36+
37+
unit-tests-83:
38+
name: Unit Tests (PHP 8.3)
39+
runs-on: ubuntu-latest
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
MAGENTO_VERSION: ["2.4.7"]
44+
steps:
45+
- uses: actions/checkout@v4
46+
- uses: extdn/github-actions-m2/magento-unit-tests/8.3@master
47+
env:
48+
MAGENTO_VERSION: ${{ matrix.MAGENTO_VERSION }}
49+
950
lint:
1051
name: ESLint
1152
runs-on: ubuntu-latest
1253
steps:
13-
- uses: actions/checkout@v3
14-
- uses: actions/setup-node@v2
54+
- uses: actions/checkout@v4
55+
- uses: actions/setup-node@v4
1556
with:
1657
node-version: ${{ env.NODE_VERSION }}
17-
58+
1859
- name: Run linter
1960
run: |
2061
composer config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true

Model/Ipn/IpnNotificationSender.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ public function execute(string $orderId): void
2828
if (!$invoiceData || !isset($invoiceData['invoice_id'])) {
2929
throw new \RuntimeException('Wrong BitPay Invoice');
3030
}
31+
$invoice = $client->getInvoice($invoiceData['invoice_id']);
32+
if (!$invoice) {
33+
throw new \RuntimeException('BitPay Invoice not found');
34+
}
3135

32-
$client->requestInvoiceNotification($invoiceData['invoice_id']);
36+
$client->requestInvoiceNotification($invoiceData['invoice_id'], $invoice->getToken());
3337
}
3438
}

Test/Unit/Model/Ipn/IpnNotificationSenderTest.php

+23-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
use Bitpay\BPCheckout\Model\BitpayInvoiceRepository;
88
use Bitpay\BPCheckout\Model\Client as ClientFactory;
99
use Bitpay\BPCheckout\Model\Ipn\IpnNotificationSender;
10+
use BitPaySDK\Model\Invoice\Buyer;
1011
use PHPUnit\Framework\TestCase;
1112

1213
class IpnNotificationSenderTest extends TestCase
1314
{
1415
private const EXISTING_ORDER_ID = '11';
1516
private const NON_EXISTING_ORDER_ID = '121312321';
1617
private const INVOICE_ID = '123';
18+
private const INVOICE_TOKEN = 'token';
1719

1820
public function testSendIpnNotification(): void
1921
{
@@ -23,8 +25,10 @@ public function testSendIpnNotification(): void
2325
$bitpayInvoiceRepository->method('getByOrderId')->with(self::EXISTING_ORDER_ID)
2426
->willReturn(['invoice_id' => self::INVOICE_ID]);
2527
$clientFactory->method('initialize')->willReturn($client);
28+
$invoice = $this->prepareInvoice();
29+
$client->expects($this->once())->method('getInvoice')->willReturn($invoice);
2630

27-
$client->expects(self::once())->method('requestInvoiceNotification')->with(self::INVOICE_ID);
31+
$client->expects(self::once())->method('requestInvoiceNotification')->with(self::INVOICE_ID, self::INVOICE_TOKEN);
2832

2933
$testedClass = $this->getTestedClass($clientFactory, $bitpayInvoiceRepository);
3034
$testedClass->execute(self::EXISTING_ORDER_ID);
@@ -39,13 +43,30 @@ public function testIncorrectSendIpnNotification(): void
3943
->willReturn(null);
4044
$clientFactory->method('initialize')->willReturn($client);
4145

42-
$client->expects(self::never())->method('requestInvoiceNotification')->with(self::INVOICE_ID);
46+
$client->expects(self::never())->method('requestInvoiceNotification')->with(self::INVOICE_ID, self::INVOICE_TOKEN);
4347
$this->expectException(\RuntimeException::class);
4448

4549
$testedClass = $this->getTestedClass($clientFactory, $bitpayInvoiceRepository);
4650
$testedClass->execute(self::NON_EXISTING_ORDER_ID);
4751
}
4852

53+
/**
54+
* @return \BitPaySDK\Model\Invoice\Invoice
55+
*/
56+
private function prepareInvoice(): \BitPaySDK\Model\Invoice\Invoice
57+
{
58+
$invoice = new \BitPaySDK\Model\Invoice\Invoice(12.00, 'USD');
59+
$invoice->setAmountPaid(1232132);
60+
$invoice->setToken(self::INVOICE_TOKEN);
61+
$buyer = new Buyer();
62+
$buyer->setName('test');
63+
$buyer->setEmail('[email protected]');
64+
$buyer->setAddress1('12 test road');
65+
$invoice->setBuyer($buyer);
66+
67+
return $invoice;
68+
}
69+
4970
private function getTestedClass(ClientFactory $clientFactory, BitpayInvoiceRepository $bitpayInvoiceRepository)
5071
{
5172
return new IpnNotificationSender($clientFactory, $bitpayInvoiceRepository);

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"minimum-stability": "stable",
1414
"require": {
1515
"php": "~8.1",
16-
"bitpay/sdk": "^9.1"
16+
"bitpay/sdk": "^9.2"
1717
},
1818
"autoload": {
1919
"files": [

0 commit comments

Comments
 (0)