Skip to content

Commit bf47e77

Browse files
Added QRCode test cases.
1 parent 283798d commit bf47e77

File tree

5 files changed

+151
-5
lines changed

5 files changed

+151
-5
lines changed

src/Message/AbstractIncomingRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public function getData(): array
3232
*/
3333
public function initialize(array $parameters = []): self
3434
{
35-
parent::initialize();
35+
parent::initialize($parameters);
3636

37-
$this->parameters->replace(
38-
$this->getIncomingParameters()
39-
);
37+
foreach ($this->getIncomingParameters() as $parameter => $value) {
38+
$this->setParameter($parameter, $value);
39+
}
4040

4141
return $this;
4242
}

src/Support/Arr.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Arr
1212
/**
1313
* Hổ trợ lấy giá trị trong mảng với định dạng 'a.b.c'
1414
*
15-
* @param $element
15+
* @param mixed $element
1616
* @param array $arr
1717
* @param null $default
1818
* @return mixed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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\QRCode\Message;
9+
10+
use Omnipay\Tests\TestCase;
11+
use Omnipay\MoMo\Message\QRCode\NotificationRequest;
12+
13+
/**
14+
* @author Vuong Minh <[email protected]>
15+
* @since 1.0.0
16+
*/
17+
class NotificationRequestTest extends TestCase
18+
{
19+
/**
20+
* @var NotificationRequest
21+
*/
22+
private $request;
23+
24+
public function setUp()
25+
{
26+
$client = $this->getHttpClient();
27+
$request = $this->getHttpRequest();
28+
$request->initialize([], [], [], [], [], [], '{"partnerCode":"MOMO0HGO20180417","accessKey":"E8HZuQRy2RsjVtZp","amount":10000,"partnerRefId":"B001221","partnerTransId":"","transType":"momo_wallet","momoTransId":"43121679","status":0,"message":"Th\u00e0nh C\u00f4ng","responseTime":1555472829549,"storeId":"store001","signature":"f25c699ee9c961eaca8f91227413877d4c7ce6818342abdcf014d5f799a953d3"}');
29+
$this->request = new NotificationRequest($client, $request);
30+
}
31+
32+
public function testGetData()
33+
{
34+
$data = $this->request->getData();
35+
$this->assertEquals(12, count($data));
36+
$this->assertEquals('MOMO0HGO20180417', $data['partnerCode']);
37+
$this->assertEquals('E8HZuQRy2RsjVtZp', $data['accessKey']);
38+
$this->assertEquals(10000, $data['amount']);
39+
$this->assertEquals('B001221', $data['partnerRefId']);
40+
$this->assertEquals('', $data['partnerTransId']);
41+
$this->assertEquals('momo_wallet', $data['transType']);
42+
$this->assertEquals(43121679, $data['momoTransId']);
43+
$this->assertEquals(1555472829549, $data['responseTime']);
44+
}
45+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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\QRCode\Message;
9+
10+
use Omnipay\Tests\TestCase;
11+
use Omnipay\MoMo\Message\QRCode\NotificationResponse;
12+
13+
/**
14+
* @author Vuong Minh <[email protected]>
15+
* @since 1.0.0
16+
*/
17+
class NotificationResponseTest extends TestCase
18+
{
19+
public function testConstruct()
20+
{
21+
$response = new NotificationResponse($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+
$request = $this->getMockRequest();
32+
$request->shouldReceive('getParameters')->once()->andReturn([
33+
'secretKey' => 'fj00YKnJhmYqahaFWUgkg75saNTzMrbO',
34+
]);
35+
$response = new NotificationResponse(
36+
$request,
37+
[
38+
'partnerCode' => 'MOMO0HGO20180417',
39+
'accessKey' => 'E8HZuQRy2RsjVtZp',
40+
'amount' => 10000,
41+
'partnerRefId' => 'B001221',
42+
'partnerTransId' => '',
43+
'transType' => 'momo_wallet',
44+
'momoTransId' => '43121679',
45+
'status' => 0,
46+
'message' => 'Thành Công',
47+
'responseTime' => 1555472829549,
48+
'storeId' => 'store001',
49+
'signature' => 'f25c699ee9c961eaca8f91227413877d4c7ce6818342abdcf014d5f799a953d3',
50+
]
51+
);
52+
53+
$this->assertSame('MOMO0HGO20180417', $response->partnerCode);
54+
$this->assertSame('momo_wallet', $response->transType);
55+
}
56+
}

tests/QRCode/QRCodeGatewayTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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\QRCode;
9+
10+
use Omnipay\Omnipay;
11+
use Omnipay\Tests\GatewayTestCase;
12+
13+
/**
14+
* @author Vuong Minh <[email protected]>
15+
* @since 1.0.0
16+
*/
17+
class QRCodeGatewayTest extends GatewayTestCase
18+
{
19+
protected function setUp()
20+
{
21+
$this->gateway = Omnipay::create('MoMo_QRCode', $this->getHttpClient(), $this->getHttpRequest());
22+
$this->gateway->setAccessKey('E8HZuQRy2RsjVtZp');
23+
$this->gateway->setPartnerCode('MOMO0HGO20180417');
24+
$this->gateway->setSecretKey('fj00YKnJhmYqahaFWUgkg75saNTzMrbO');
25+
$this->gateway->setTestMode(true);
26+
27+
parent::setUp();
28+
}
29+
30+
public function testNotification()
31+
{
32+
$this->getHttpRequest()->initialize([], [], [], [], [], [], '{"partnerCode":"MOMO0HGO20180417","accessKey":"E8HZuQRy2RsjVtZp","amount":10000,"partnerRefId":"B001221","partnerTransId":"","transType":"momo_wallet","momoTransId":"43121679","status":0,"message":"Th\u00e0nh C\u00f4ng","responseTime":1555472829549,"storeId":"store001","signature":"f25c699ee9c961eaca8f91227413877d4c7ce6818342abdcf014d5f799a953d3"}');
33+
$response = $this->gateway->notification()->send();
34+
$this->assertTrue($response->isSuccessful());
35+
$this->assertEquals('MOMO0HGO20180417', $response->partnerCode);
36+
}
37+
38+
/**
39+
* @doesNotPerformAssertions
40+
*/
41+
public function testDefaultParametersHaveMatchingMethods()
42+
{
43+
parent::testDefaultParametersHaveMatchingMethods();
44+
}
45+
}

0 commit comments

Comments
 (0)