Skip to content

Commit c5969d7

Browse files
committed
Add PHP 8.5 support; add EEC_TERMINAL_LOCKED error code
1 parent 026f961 commit c5969d7

13 files changed

Lines changed: 51 additions & 85 deletions

File tree

.github/workflows/php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
operating-system: [ubuntu-latest]
11-
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
11+
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
1212
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
1313

1414
steps:

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
"psr-4": {"TransactPro\\Gateway\\": "tests/Gateway"}
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": "^6.0 | ^9.5",
20-
"php-parallel-lint/php-parallel-lint": "^1.3",
21-
"friendsofphp/php-cs-fixer": "^3.1",
22-
"phpstan/phpstan": "^1.9"
19+
"phpunit/phpunit": "^6.0 | ^9.5 | ^13.1",
20+
"php-parallel-lint/php-parallel-lint": "^1.3 | ^1.4",
21+
"friendsofphp/php-cs-fixer": "^3.1 | ^3.95",
22+
"phpstan/phpstan": "^1.9 | ^2.1"
2323
},
2424
"scripts": {
2525
"test": [
2626
"./vendor/bin/parallel-lint . --exclude vendor",
2727
"./vendor/bin/phpstan analyse --level 5 src tests",
28-
"./vendor/bin/phpunit",
28+
"./vendor/bin/phpunit --display-deprecations --display-notices --display-warnings",
2929
"./vendor/bin/php-cs-fixer fix --using-cache=no --dry-run"
3030
],
3131
"cs": "./vendor/bin/php-cs-fixer fix --using-cache=no"

phpunit.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3-
<coverage>
4-
<include>
5-
<directory suffix=".php">src/Gateway/</directory>
6-
</include>
7-
</coverage>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/13.1/phpunit.xsd">
83
<testsuites>
94
<testsuite name="GW3 Test Suite">
105
<directory>tests/Gateway/</directory>
@@ -13,4 +8,9 @@
138
<php>
149
<ini name="date.timezone" value="UTC"/>
1510
</php>
11+
<source>
12+
<include>
13+
<directory suffix=".php">src/Gateway/</directory>
14+
</include>
15+
</source>
1616
</phpunit>

src/Gateway/Gateway.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ public function createRetrieveForm(PaymentResponse $paymentResponse): RetrieveFo
477477
public function process(Request $request)
478478
{
479479
$payload = $request->getPreparedData();
480-
if (empty($payload) && strtolower($request->getMethod()) !== 'GET') {
480+
if (empty($payload) && strtolower($request->getMethod()) !== 'get') {
481481
$payload = $this->generatePayload($request->getData());
482482
$request->setPreparedData($payload);
483483
}

src/Gateway/Http/Crypto/ResponseDigest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function __construct(?string $authorizationHeader = null)
6767
'qop' => [self::QOP_AUTH, self::QOP_AUTH_INT],
6868
];
6969
foreach ($headerValues as $key => $value) {
70-
if (!isset($value) || !is_string($value)) {
70+
if (!isset($value)) {
7171
throw new DigestMismatchException("Digest mismatch: empty value for $key");
7272
}
7373

src/Gateway/Http/Transport/Curl.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ public function getStatus(): int
217217
*/
218218
public function close()
219219
{
220-
if (!empty($this->ch)) {
220+
// @phpstan-ignore identical.alwaysTrue
221+
if (!empty($this->ch) && (PHP_MAJOR_VERSION < 8 || (PHP_MAJOR_VERSION === 8 && PHP_MINOR_VERSION < 5))) {
221222
curl_close($this->ch);
222-
223-
$this->ch = null;
224223
}
224+
$this->ch = null;
225225
}
226226
}

src/Gateway/Responses/Constants/ErrorCode.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class ErrorCode
6868

6969
const EEC_TERMINAL_NOT_SUPPORTING_MOTO = 1204;
7070
const EEC_TERMINAL_NOT_SUPPORTING_RECURRENTS = 1205;
71+
const EEC_TERMINAL_LOCKED = 1206;
7172

7273
const EEC_DECLINED_BY_ACQUIRER = 1301;
7374
const EEC_ACQUIRER_ERROR = 1302;

tests/Gateway/GatewayTest.php

Lines changed: 15 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace TransactPro\Gateway;
1313

14-
use PHPUnit\Framework\MockObject\MockObject;
1514
use PHPUnit\Framework\TestCase;
1615
use TransactPro\Gateway\DataSets\Auth;
1716
use TransactPro\Gateway\Exceptions\GatewayException;
@@ -46,63 +45,21 @@ class GatewayTest extends TestCase
4645
public function testGateway(): void
4746
{
4847
$gw = new Gateway();
49-
$csvResponseMock = $this->createMock(CsvResponse::class);
50-
51-
/** @var HttpClientInterface|MockObject $httpClientStub */
52-
$httpClientStub = $this->createMock(HttpClientInterface::class);
53-
$httpClientStub->method('request')->willReturn(new class($csvResponseMock) implements ResponseInterface {
54-
private $csvResponseMock;
55-
56-
public function __construct($csvResponseMock)
57-
{
58-
$this->csvResponseMock = $csvResponseMock;
59-
}
60-
61-
public function getStatusCode(): int
62-
{
63-
return 200;
64-
}
65-
66-
public function setHeader(string $header, string $value): ResponseInterface
67-
{
68-
return $this;
69-
}
70-
71-
public function getHeaders(): array
72-
{
73-
return [];
74-
}
75-
76-
public function getHeader(string $header): string
77-
{
78-
return 'aaa';
79-
}
80-
81-
public function getBody(): string
82-
{
83-
return 'holy moly';
84-
}
85-
86-
public function isSuccessful(): bool
87-
{
88-
return true;
89-
}
90-
91-
public function getDigest()
92-
{
93-
return null;
94-
}
95-
96-
public function parseJSON(string $targetClass)
97-
{
98-
return null;
99-
}
100-
101-
public function parseCsv(): CsvResponse
102-
{
103-
return $this->csvResponseMock;
104-
}
105-
});
48+
$csvResponseStub = $this->createStub(CsvResponse::class);
49+
50+
$responseStub = $this->createStub(ResponseInterface::class);
51+
$responseStub->method('getStatusCode')->willReturn(200);
52+
$responseStub->method('setHeader')->willReturnSelf();
53+
$responseStub->method('getHeaders')->willReturn([]);
54+
$responseStub->method('getHeader')->willReturn('aaa');
55+
$responseStub->method('getBody')->willReturn('holy moly');
56+
$responseStub->method('isSuccessful')->willReturn(true);
57+
$responseStub->method('getDigest')->willReturn(null);
58+
$responseStub->method('parseJSON')->willReturn(null);
59+
$responseStub->method('parseCsv')->willReturn($csvResponseStub);
60+
61+
$httpClientStub = $this->createStub(HttpClientInterface::class);
62+
$httpClientStub->method('request')->willReturn($responseStub);
10663

10764
$gw->setHttpClient($httpClientStub);
10865

tests/Gateway/Http/Client/ClientTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace TransactPro\Gateway\Http\Client;
1313

14-
use PHPUnit\Framework\MockObject\MockObject;
1514
use PHPUnit\Framework\TestCase;
1615
use TransactPro\Gateway\Exceptions\RequestException;
1716
use TransactPro\Gateway\Interfaces\HttpTransportInterface;
@@ -20,8 +19,7 @@ class ClientTest extends TestCase
2019
{
2120
public function testClientSuccess(): void
2221
{
23-
/** @var HttpTransportInterface|MockObject $stubTransport */
24-
$stubTransport = $this->createMock(HttpTransportInterface::class);
22+
$stubTransport = $this->createStub(HttpTransportInterface::class);
2523

2624
$stubTransport->method('execute')->willReturn(true);
2725
$stubTransport->method('getStatus')->willReturn(404);
@@ -42,8 +40,7 @@ public function testClientRequestException(): void
4240
$this->expectException(RequestException::class);
4341
$this->expectExceptionMessage('custom error');
4442

45-
/** @var HttpTransportInterface|MockObject $stubTransport */
46-
$stubTransport = $this->createMock(HttpTransportInterface::class);
43+
$stubTransport = $this->createStub(HttpTransportInterface::class);
4744

4845
$stubTransport->method('execute')->willReturn(false);
4946
$stubTransport->method('error')->willReturn('custom error');

tests/Gateway/Http/Crypto/RequestDigestTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public function testCreateHeader(): void
4040

4141
$rc = new ReflectionClass($instance);
4242
$oProperty = $rc->getProperty('cnonce');
43-
$oProperty->setAccessible(true);
43+
if (PHP_VERSION_ID < 80100) {
44+
$oProperty->setAccessible(true);
45+
}
4446
$oProperty->setValue($instance, base64_decode("MTU5MTYyNTA2MzqydV+lpoF4ZtfSAifxoUretZdAzGaZa97iRogrQ8K/yg=="));
4547

4648
$actual = $instance->createHeader();

0 commit comments

Comments
 (0)