Skip to content

Commit d4a853d

Browse files
Complete app in app test cases.
1 parent a49bc29 commit d4a853d

File tree

5 files changed

+143
-4
lines changed

5 files changed

+143
-4
lines changed

tests/AppInApp/AppInAppGatewayTest.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,30 @@ protected function setUp()
3434
parent::setUp();
3535
}
3636

37-
public function testPurchase()
37+
public function testPurchaseSuccess()
3838
{
3939
$this->setMockHttpResponse('PurchaseSuccess.txt');
40-
$this->gateway->purchase([
40+
$response = $this->gateway->purchase([
4141
'customerNumber' => '0909113911',
4242
'appData' => 'holo',
4343
'partnerRefId' => 99,
44-
'amount' => 50000,
44+
'amount' => 40000,
4545
])->send();
46+
$this->assertTrue($response->isSuccessful());
47+
$this->assertEquals(40000, $response->amount);
48+
}
49+
50+
public function testPurchaseFailure()
51+
{
52+
$this->setMockHttpResponse('PurchaseFailure.txt');
53+
$response = $this->gateway->purchase([
54+
'customerNumber' => '0909113911',
55+
'appData' => 'holo',
56+
'partnerRefId' => 99,
57+
'amount' => 10000,
58+
])->send();
59+
$this->assertFalse($response->isSuccessful());
60+
$this->assertEquals(10000, $response->amount);
4661
}
4762

4863
/**
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/omnipay-momo
4+
* @copyright (c) PHP Viet
5+
* @license [MIT](http://www.opensource.org/licenses/MIT)
6+
*/
7+
8+
namespace Omnipay\MoMo\Tests\AppInApp\Message;
9+
10+
use Omnipay\Tests\TestCase;
11+
use Omnipay\MoMo\Message\AppInApp\PurchaseRequest;
12+
13+
/**
14+
* @author Vuong Minh <[email protected]>
15+
* @since 1.0.0
16+
*/
17+
class PurchaseRequestTest extends TestCase
18+
{
19+
/**
20+
* @var PurchaseRequest
21+
*/
22+
private $request;
23+
24+
public function setUp()
25+
{
26+
$client = $this->getHttpClient();
27+
$request = $this->getHttpRequest();
28+
$this->request = new PurchaseRequest($client, $request);
29+
}
30+
31+
public function testGetData()
32+
{
33+
$this->request->setPartnerRefId(1);
34+
$this->request->setAppData(2);
35+
$this->request->setAmount(3);
36+
$this->request->setPartnerCode(4);
37+
$this->request->setPartnerTransId(5);
38+
$this->request->setCustomerNumber(6);
39+
$this->request->setTestMode(true);
40+
$this->request->setPublicKey('-----BEGIN PUBLIC KEY-----
41+
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAiBIo9EMTElPppPejirL1cdgCuZUoBzGZ
42+
F3SyrTp+xdMnIXSOiFYG+zHmI1lFzoEbEd1JwXAUV52gn/oAkUo+2qwuqZAPdkm714tiyjvxXE/0
43+
WYLl8X1K8uCSK47u26CnOLgNB6iW1m9jog00i9XV/AmKI1U8OioLFSp1BwMf3O+jA9uuRfj1Lv5Q
44+
0Q7RMtk4tgV924+D8mY/y3otBp5b+zX0NrWkRqwgPly6NeXN5LwqRj0LwAEVVwGbpl6V2cztYv94
45+
ZHjGzNziFJli2D0Vpb/HRPP6ibXvllgbL4UXU4Izqhxml8gwd74jXaNaEgNJGhjjeUXR1sAm7Mpj
46+
qqgyxpx6B2+GpjWtEwvbJuO8DsmQNsm+bJZhw46uf9AuY5VSYy2cAF1XMXSAPNLqYEE8oVUki4IW
47+
YOEWSNXcQwikJC25rAErbyst/0i8RN4yqgiO/xVA1J1vdmRQTvGMXPGbDFpVca4MkHHLrkdC3Z3C
48+
zgMkbIqnpaDYoIHZywraHWA7Zh5fDt/t7FzX69nbGg8i4QFLzIm/2RDPePJTY2R24w1iVO5RhEbK
49+
EaTBMuibp4UJH+nEQ1p6CNdHvGvWz8S0izfiZmYIddaPatQTxYRq4rSsE/+2L+9RE9HMqAhQVveh
50+
RGWWiGSY1U4lWVeTGq2suCNcMZdgDMbbIaSEJJRQTksCAwEAAQ==
51+
-----END PUBLIC KEY-----');
52+
$data = $this->request->getData();
53+
$this->assertEquals(9, count($data));
54+
$this->assertEquals(1, $data['partnerRefId']);
55+
$this->assertEquals(3, $data['amount']);
56+
$this->assertEquals(4, $data['partnerCode']);
57+
$this->assertEquals(5, $data['partnerTransId']);
58+
$this->assertEquals(6, $data['customerNumber']);
59+
$this->assertEquals(null, $data['secretKey'] ?? null);
60+
$this->assertEquals(null, $data['publicKey'] ?? null);
61+
$this->assertEquals(null, $data['paymentCode'] ?? null);
62+
$this->assertEquals(null, $data['testMode'] ?? null);
63+
$this->assertTrue(isset($data['hash']));
64+
$this->assertTrue(isset($data['version']));
65+
$this->assertTrue(isset($data['payType']));
66+
}
67+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/omnipay-momo
4+
* @copyright (c) PHP Viet
5+
* @license [MIT](http://www.opensource.org/licenses/MIT)
6+
*/
7+
8+
namespace Omnipay\MoMo\Tests\AppInApp\Message;
9+
10+
use Omnipay\Tests\TestCase;
11+
use Omnipay\MoMo\Message\AppInApp\PurchaseResponse;
12+
13+
/**
14+
* @author Vuong Minh <[email protected]>
15+
* @since 1.0.0
16+
*/
17+
class PurchaseResponseTest extends TestCase
18+
{
19+
public function testConstruct()
20+
{
21+
$response = new PurchaseResponse($this->getMockRequest(), [
22+
'example' => 'value',
23+
'foo' => 'bar',
24+
]);
25+
26+
$this->assertEquals(['example' => 'value', 'foo' => 'bar'], $response->getData());
27+
}
28+
29+
public function testResponse()
30+
{
31+
$httpResponse = $this->getMockHttpResponse('PurchaseSuccess.txt');
32+
$request = $this->getMockRequest();
33+
$request->shouldReceive('getParameters')->once()->andReturn([
34+
'secretKey' => 'fj00YKnJhmYqahaFWUgkg75saNTzMrbO',
35+
]);
36+
$response = new PurchaseResponse(
37+
$request,
38+
json_decode($httpResponse->getBody()->getContents(), true)
39+
);
40+
41+
$this->assertEquals('43121679', $response->transid);
42+
$this->assertEquals('40000', $response->amount);
43+
}
44+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
HTTP/1.1 200 OK
2+
Server: nginx
3+
Date: Tue, 25 Jun 2019 08:56:42 GMT
4+
Content-Type: application/json; charset=utf-8
5+
Transfer-Encoding: chunked
6+
Connection: keep-alive
7+
Vary: Accept-Encoding
8+
X-Kong-Upstream-Latency: 310
9+
X-Kong-Proxy-Latency: 1
10+
Via: kong/0.14.1
11+
Strict-Transport-Security: max-age=15768000
12+
13+
{"status":99,"message":"Th\u1ea5t b\u1ea1i","amount":10000}

tests/AppInApp/Mock/PurchaseSuccess.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ X-Kong-Proxy-Latency: 1
1010
Via: kong/0.14.1
1111
Strict-Transport-Security: max-age=15768000
1212

13-
{"status":0,"message":"Thành công","amount":40000,"transid":"43121679","signature":"307b0ee753798e3aff6eb69b2d7966bf0fab29f88336ce0763532fcfafadbe28"}
13+
{"status":0,"message":"Th\u00e0nh c\u00f4ng","amount":40000,"transid":"43121679","signature":"a55801bf4657fe8bbf708a56c9776c067bbd14fee5c69a2225bfd97a479bcc42"}

0 commit comments

Comments
 (0)