Skip to content

Commit 5369d97

Browse files
committed
test for CreatePaymentMethodRequest.cardholderName
1 parent 0b00be1 commit 5369d97

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

src/Message/CreatePaymentMethodRequest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ class CreatePaymentMethodRequest extends AbstractRequest
1414
public function getData()
1515
{
1616
$data = array(
17-
'cardholderName' => $this->getCardholderName(),
1817
'customerId' => $this->getCustomerId(),
1918
'paymentMethodNonce' => $this->getToken(),
2019
);
20+
if ($cardholderName = $this->getCardholderName()) {
21+
$data['cardholderName'] = $cardholderName;
22+
}
2123
$data += $this->getOptionData();
2224

2325
return $data;

tests/Message/CreatePaymentMethodRequestTest.php

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,59 @@
66

77
class CreatePaymentMethodRequestTest extends TestCase
88
{
9-
/**
10-
* @var CreatePaymentMethodRequest
11-
*/
12-
private $request;
13-
14-
public function setUp()
9+
public function testGetData()
1510
{
16-
$this->request = new CreatePaymentMethodRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway());
17-
$this->request->initialize(
11+
$request = $this->createPaymentMethodRequest();
12+
$request->initialize(
1813
array(
1914
'customerId' => '4815162342',
2015
'token' => 'abc123',
2116
'verifyCard' => true,
2217
'verificationMerchantAccountId' => '123581321',
2318
)
2419
);
20+
21+
$expectedData = array(
22+
'customerId' => '4815162342',
23+
'paymentMethodNonce' => 'abc123',
24+
'options' => array(
25+
'verifyCard' => true,
26+
'verificationMerchantAccountId' => '123581321',
27+
)
28+
);
29+
$this->assertSame($expectedData, $request->getData());
2530
}
2631

27-
public function testGetData()
32+
public function testGetDataWithCardholderName()
2833
{
34+
$request = $this->createPaymentMethodRequest();
35+
$request->initialize(
36+
array(
37+
'customerId' => '4815162342',
38+
'token' => 'abc123',
39+
'cardholderName' => 'John Yolo',
40+
'verifyCard' => true,
41+
'verificationMerchantAccountId' => '123581321',
42+
)
43+
);
44+
2945
$expectedData = array(
3046
'customerId' => '4815162342',
3147
'paymentMethodNonce' => 'abc123',
48+
'cardholderName' => 'John Yolo',
3249
'options' => array(
3350
'verifyCard' => true,
3451
'verificationMerchantAccountId' => '123581321',
3552
)
3653
);
37-
$this->assertSame($expectedData, $this->request->getData());
54+
$this->assertSame($expectedData, $request->getData());
55+
}
56+
57+
/**
58+
* @return CreatePaymentMethodRequest
59+
*/
60+
private function createPaymentMethodRequest()
61+
{
62+
return new CreatePaymentMethodRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway());
3863
}
3964
}

0 commit comments

Comments
 (0)