Skip to content

Commit 2a786c4

Browse files
added tests and fixed access issues
1 parent e8919dc commit 2a786c4

File tree

2 files changed

+93
-4
lines changed

2 files changed

+93
-4
lines changed

src/Hyperwallet/Hyperwallet.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ public function __construct($username, $password, $programToken = null, $server
9191
* @return array
9292
*/
9393
private function setDocumentAndReasonFromResponseHelper($bodyResponse) {
94-
$documents = $bodyResponse["documents"];
95-
if ($documents) {
94+
if (array_key_exists("documents", $bodyResponse)) {
95+
$documents = $bodyResponse["documents"];
9696
foreach ($documents as &$dVal) {
97-
$reasons = $dVal["reasons"];
98-
if ($reasons) {
97+
if (array_key_exists("reasons", $dVal)) {
98+
$reasons = $dVal["reasons"];
9999
foreach ($reasons as &$rVal) {
100100
$rVal = new HyperwalletVerificationDocumentReason($rVal);
101101
}

tests/Hyperwallet/Tests/HyperwalletTest.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4081,6 +4081,26 @@ public static function UPLOAD_REASON_DATA() {
40814081
);
40824082
}
40834083

4084+
public static function UPLOAD_REASON_DATA_NO_REASON() {
4085+
return array(
4086+
'token' => 'tkn-12345',
4087+
"documents" => array( array(
4088+
"category" => "IDENTIFICATION",
4089+
"type" => "PASSPORT",
4090+
"country" => "ES",
4091+
"status" => "NEW",
4092+
"createdOn" => "2020-11-24T19:05:02"
4093+
4094+
))
4095+
);
4096+
}
4097+
4098+
public static function UPLOAD_REASON_DATA_NO_DOC() {
4099+
return array(
4100+
'token' => 'tkn-12345',
4101+
);
4102+
}
4103+
40844104
public function testuploadDocumentsForUser_withoutUserToken() {
40854105
// Setup
40864106
$client = new Hyperwallet('test-username', 'test-password');
@@ -4199,6 +4219,75 @@ public function testuploadDocumentsForUser_parseReasons() {
41994219
\Phake::verify($apiClientMock)->putMultipartData('/rest/v3/users/{user-token}', array('user-token' => $userToken), $options);
42004220
}
42014221

4222+
public function testuploadDocumentsForUser_parseNoReasons() {
4223+
// Setup
4224+
$client = new Hyperwallet('test-username', 'test-password');
4225+
$apiClientMock = $this->createAndInjectApiClientMock($client);
4226+
$userToken = "user-token";
4227+
4228+
$options = array(
4229+
'multipart' => [
4230+
[
4231+
'name' => 'data',
4232+
'contents' => '{"documents":[{"type":"DRIVERS_LICENSE","country":"AL","category":"IDENTIFICATION"}]}'
4233+
],
4234+
[
4235+
'name' => 'drivers_license_front',
4236+
'contents' => fopen(__DIR__ . "/../../resources/license-front.png", "r")
4237+
],
4238+
[
4239+
'name' => 'drivers_license_back',
4240+
'contents' => fopen(__DIR__ . "/../../resources/license-back.png", 'r')
4241+
]
4242+
]
4243+
);
4244+
4245+
\Phake::when($apiClientMock)->putMultipartData('/rest/v3/users/{user-token}', array('user-token' => $userToken), $options)->thenReturn($this->UPLOAD_REASON_DATA_NO_REASON());
4246+
// Run test
4247+
$newUser = $client->uploadDocumentsForUser($userToken, $options);
4248+
$this->assertNotNull($newUser);
4249+
$this->assertNull($newUser->getProgramToken());
4250+
$this->assertEquals($this->UPLOAD_REASON_DATA_NO_REASON()["documents"][0]["type"], $newUser->documents->documents[0]->type);
4251+
4252+
// Validate mock
4253+
\Phake::verify($apiClientMock)->putMultipartData('/rest/v3/users/{user-token}', array('user-token' => $userToken), $options);
4254+
}
4255+
4256+
public function testuploadDocumentsForUser_parseNoDocument() {
4257+
// Setup
4258+
$client = new Hyperwallet('test-username', 'test-password');
4259+
$apiClientMock = $this->createAndInjectApiClientMock($client);
4260+
$userToken = "user-token";
4261+
4262+
$options = array(
4263+
'multipart' => [
4264+
[
4265+
'name' => 'data',
4266+
'contents' => '{"documents":[{"type":"DRIVERS_LICENSE","country":"AL","category":"IDENTIFICATION"}]}'
4267+
],
4268+
[
4269+
'name' => 'drivers_license_front',
4270+
'contents' => fopen(__DIR__ . "/../../resources/license-front.png", "r")
4271+
],
4272+
[
4273+
'name' => 'drivers_license_back',
4274+
'contents' => fopen(__DIR__ . "/../../resources/license-back.png", 'r')
4275+
]
4276+
]
4277+
);
4278+
4279+
\Phake::when($apiClientMock)->putMultipartData('/rest/v3/users/{user-token}', array('user-token' => $userToken), $options)->thenReturn($this->UPLOAD_REASON_DATA_NO_DOC());
4280+
4281+
// Run test
4282+
$newUser = $client->uploadDocumentsForUser($userToken, $options);
4283+
$this->assertNotNull($newUser);
4284+
$this->assertNull($newUser->getProgramToken());
4285+
$this->assertEquals($this->UPLOAD_REASON_DATA_NO_DOC()["token"], $newUser->token);
4286+
4287+
// Validate mock
4288+
\Phake::verify($apiClientMock)->putMultipartData('/rest/v3/users/{user-token}', array('user-token' => $userToken), $options);
4289+
}
4290+
42024291

42034292
//--------------------------------------
42044293
// Venmo Accounts

0 commit comments

Comments
 (0)