Skip to content

Commit b778540

Browse files
committed
Test abstract request methods
1 parent afa334d commit b778540

File tree

3 files changed

+174
-10
lines changed

3 files changed

+174
-10
lines changed

src/Message/AbstractRequest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public function setTaxExempt($value)
272272
/**
273273
* @return array
274274
*/
275-
protected function getCardData()
275+
public function getCardData()
276276
{
277277
$card = $this->getCard();
278278

@@ -293,15 +293,15 @@ protected function getCardData()
293293
'countryName' => $card->getBillingCountry(),
294294
),
295295
'shipping' => array(
296-
'company' => $card->getShippingCompany(),
297-
'firstName' => $card->getShippingFirstName(),
298-
'lastName' => $card->getShippingLastName(),
299-
'streetAddress' => $card->getShippingAddress1(),
300-
'extendedAddress' => $card->getShippingAddress2(),
301-
'locality' => $card->getShippingCity(),
302-
'postalCode' => $card->getShippingPostcode(),
303-
'region' => $card->getShippingState(),
304-
'countryName' => $card->getShippingCountry(),
296+
'company' => $card->getShippingCompany(),
297+
'firstName' => $card->getShippingFirstName(),
298+
'lastName' => $card->getShippingLastName(),
299+
'streetAddress' => $card->getShippingAddress1(),
300+
'extendedAddress' => $card->getShippingAddress2(),
301+
'locality' => $card->getShippingCity(),
302+
'postalCode' => $card->getShippingPostcode(),
303+
'region' => $card->getShippingState(),
304+
'countryName' => $card->getShippingCountry(),
305305
)
306306
);
307307
}

tests/Message/AbstractRequestTest.php

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
3+
namespace Omnipay\Braintree\Message;
4+
5+
use Mockery;
6+
use Omnipay\Tests\TestCase;
7+
8+
class AbstractRequestTest extends TestCase
9+
{
10+
/**
11+
* @var AbstractRequest
12+
*/
13+
private $request;
14+
15+
public function setUp()
16+
{
17+
$this->request = Mockery::mock('\Omnipay\Braintree\Message\AbstractRequest')->makePartial();
18+
$this->request->initialize();
19+
}
20+
21+
/**
22+
* @dataProvider provideKeepsData
23+
* @param string $field
24+
* @param string $value
25+
*/
26+
public function testKeepsData($field, $value)
27+
{
28+
$field = ucfirst($field);
29+
$this->assertSame($this->request, $this->request->{"set$field"}($value));
30+
$this->assertSame($value, $this->request->{"get$field"}());
31+
}
32+
33+
public function provideKeepsData(){
34+
return array(
35+
array('token', 'abc123'),
36+
array('merchantId', 'abc123'),
37+
array('publicKey', 'abc123'),
38+
array('privateKey', 'abc123'),
39+
array('billingAddressId', 'abc123'),
40+
array('channel', 'abc123'),
41+
array('customFields', ['a' => 'b']),
42+
array('customerId', 'abc123'),
43+
array('descriptor', array('a' => 'b')),
44+
array('deviceData', 'abc123'),
45+
array('deviceSessionId', 'abc123'),
46+
array('merchantAccountId', 'abc123'),
47+
array('recurring', true),
48+
array('addBillingAddressToPaymentMethod', true),
49+
array('holdInEscrow', true),
50+
array('storeInVault', true),
51+
array('storeShippingAddressInVault', true),
52+
array('shippingAddressId', 'abc123'),
53+
array('taxAmount', '10.00'),
54+
array('taxExempt', true),
55+
);
56+
}
57+
58+
/**
59+
* @dataProvider provideMakesBool
60+
* @param string $field
61+
*/
62+
public function testMakesBool($field)
63+
{
64+
$field = ucfirst($field);
65+
66+
$this->assertSame($this->request, $this->request->{"set$field"}(0));
67+
$this->assertSame(false, $this->request->{"get$field"}());
68+
69+
$this->assertSame($this->request, $this->request->{"set$field"}(1));
70+
$this->assertSame(true, $this->request->{"get$field"}());
71+
}
72+
73+
public function provideMakesBool(){
74+
return array(
75+
array('recurring'),
76+
array('addBillingAddressToPaymentMethod'),
77+
array('holdInEscrow'),
78+
array('storeInVault'),
79+
array('storeInVaultOnSuccess'),
80+
array('storeShippingAddressInVault'),
81+
);
82+
}
83+
84+
public function testCardData()
85+
{
86+
$card = array(
87+
'firstName' => 'Example',
88+
'lastName' => 'User',
89+
'company' => 'League',
90+
'billingAddress1' => '123 Billing St',
91+
'billingAddress2' => 'Billsville',
92+
'billingCity' => 'Billstown',
93+
'billingPostcode' => '12345',
94+
'billingState' => 'CA',
95+
'billingCountry' => 'US',
96+
'billingPhone' => '(555) 123-4567',
97+
'shippingAddress1' => '123 Shipping St',
98+
'shippingAddress2' => 'Shipsville',
99+
'shippingCity' => 'Shipstown',
100+
'shippingPostcode' => '54321',
101+
'shippingState' => 'NY',
102+
'shippingCountry' => 'US',
103+
);
104+
105+
$this->request->setCard($card);
106+
$data = $this->request->getCardData();
107+
108+
$this->assertSame($card['firstName'], $data['billing']['firstName']);
109+
$this->assertSame($card['lastName'], $data['billing']['lastName']);
110+
$this->assertSame($card['company'], $data['billing']['company']);
111+
$this->assertSame($card['billingAddress1'], $data['billing']['streetAddress']);
112+
$this->assertSame($card['billingAddress2'], $data['billing']['extendedAddress']);
113+
$this->assertSame($card['billingCity'], $data['billing']['locality']);
114+
$this->assertSame($card['billingPostcode'], $data['billing']['postalCode']);
115+
$this->assertSame($card['billingState'], $data['billing']['region']);
116+
$this->assertSame($card['billingCountry'], $data['billing']['countryName']);
117+
118+
$this->assertSame($card['firstName'], $data['shipping']['firstName']);
119+
$this->assertSame($card['lastName'], $data['shipping']['lastName']);
120+
$this->assertSame($card['company'], $data['shipping']['company']);
121+
$this->assertSame($card['shippingAddress1'], $data['shipping']['streetAddress']);
122+
$this->assertSame($card['shippingAddress2'], $data['shipping']['extendedAddress']);
123+
$this->assertSame($card['shippingCity'], $data['shipping']['locality']);
124+
$this->assertSame($card['shippingPostcode'], $data['shipping']['postalCode']);
125+
$this->assertSame($card['shippingState'], $data['shipping']['region']);
126+
$this->assertSame($card['shippingCountry'], $data['shipping']['countryName']);
127+
128+
}
129+
}

tests/Message/CaptureRequestTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Omnipay\Braintree\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class CaptureRequestTest extends TestCase
8+
{
9+
/**
10+
* @var PurchaseRequest
11+
*/
12+
private $request;
13+
14+
public function setUp()
15+
{
16+
parent::setUp();
17+
18+
$this->request = new CaptureRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway());
19+
$this->request->initialize(
20+
array(
21+
'amount' => '10.00',
22+
'transactionReference' => 'abc123',
23+
)
24+
);
25+
}
26+
27+
public function testGetData()
28+
{
29+
$data = $this->request->getData();
30+
31+
$this->assertSame('abc123', $data['transactionReference']);
32+
$this->assertSame('10.00', $data['amount']);
33+
}
34+
35+
}

0 commit comments

Comments
 (0)