Skip to content

Commit 09a821b

Browse files
committed
Adds more tests to reach above the 80% test coverage.
1 parent 0878950 commit 09a821b

File tree

5 files changed

+69
-3
lines changed

5 files changed

+69
-3
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ $data = [
8989

9090
$response = $gateway->authorize($data)->send()->getData();
9191
```
92-
This will return the order details as well as the checkout HTML snippet to render on your site.
9392

9493
[API documentation](http://docs2.icepay.com/calling-our-webservice/transaction-functions/)
9594

@@ -108,7 +107,7 @@ $success = $gateway->fetchTransaction([
108107
[API documentation](https://icepay2.docs.apiary.io/#reference/0/transaction)
109108

110109
### Refund
111-
*Do note: refunds have not been tested in production*
110+
*Do note: refunds implementation has not been tested.*
112111

113112
```php
114113
$success = $gateway->refund([
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Omnipay\IcepayPayments\Message;
4+
5+
use Omnipay\IcepayPayments\AbstractTestCase;
6+
7+
/**
8+
* Class RefundResponseTest.
9+
*/
10+
class RefundResponseTest extends AbstractTestCase
11+
{
12+
/**
13+
* @var TransactionStatusRequest
14+
*/
15+
private $request;
16+
17+
/**
18+
* Creates a new TransactionStatusRequest instance.
19+
*/
20+
protected function setUp(): void
21+
{
22+
parent::setUp();
23+
24+
$this->request = new RefundRequest($this->httpClient, $this->httpRequest);
25+
}
26+
27+
/**
28+
* Tests if TransactionStatusResponse::isSuccessful will return true with the given json response.
29+
*/
30+
public function testResponseReturnsSuccessful(): void
31+
{
32+
$responseJsonBody = file_get_contents(__DIR__.'/../Mocks/RefundSuccess.json');
33+
$response = new RefundResponse($this->request, json_decode($responseJsonBody, true));
34+
35+
$expectedResponseBody = [
36+
'RefundId' => '7c9cb2f4-83ce-4b10-8d5c-de230181224f',
37+
'RefundStatusCode' => AbstractResponse::RESPONSE_STATUS_COMPLETED,
38+
'RefundStatusDetails' => '',
39+
'AcquirerRefundId' => '',
40+
];
41+
42+
$this->assertTrue($response->isSuccessful());
43+
$this->assertSame($expectedResponseBody, $response->getData());
44+
}
45+
46+
/**
47+
* Tests if TransactionStatusResponse::isSuccessful will return false from the json response.
48+
*/
49+
public function testIfResponseReturnNotSuccessful(): void
50+
{
51+
$responseJsonBody = file_get_contents(__DIR__.'/../Mocks/RefundFail.json');
52+
$response = new RefundResponse($this->request, json_decode($responseJsonBody, true));
53+
54+
$this->assertFalse($response->isSuccessful());
55+
}
56+
}

tests/Message/TransactionStatusResponseTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ protected function setUp(): void
2222
parent::setUp();
2323

2424
$this->request = new TransactionStatusRequest($this->httpClient, $this->httpRequest);
25+
$this->request->setTransactionReference('7c9cb2f4-83ce-4b10-8d5c-de230181224f');
2526
}
2627

2728
/**
@@ -42,6 +43,7 @@ public function testResponseReturnsSuccessful(): void
4243

4344
$this->assertTrue($response->isSuccessful());
4445
$this->assertSame($expectedResponseBody, $response->getData());
46+
$this->assertSame($expectedResponseBody['transactionId'], $response->getTransactionReference());
4547
}
4648

4749
/**
@@ -50,7 +52,7 @@ public function testResponseReturnsSuccessful(): void
5052
public function testIfResponseReturnNotSuccessful(): void
5153
{
5254
$responseJsonBody = file_get_contents(__DIR__.'/../Mocks/TransactionStatusFail.json');
53-
$response = new CreateTransactionResponse($this->request, json_decode($responseJsonBody, true));
55+
$response = new TransactionStatusResponse($this->request, json_decode($responseJsonBody, true));
5456

5557
$this->assertFalse($response->isSuccessful());
5658
}

tests/Mocks/RefundFail.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"RefundStatusCode": ""
3+
}

tests/Mocks/RefundSuccess.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"RefundId": "7c9cb2f4-83ce-4b10-8d5c-de230181224f",
3+
"RefundStatusCode": "COMPLETED",
4+
"RefundStatusDetails": "",
5+
"AcquirerRefundId": ""
6+
}

0 commit comments

Comments
 (0)