Skip to content

Commit c633ec3

Browse files
author
Konstantinos Christofilos
committed
Unit tests
1 parent 33f615c commit c633ec3

File tree

3 files changed

+126
-1
lines changed

3 files changed

+126
-1
lines changed

tests/GatewayTest.php

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Omnipay\Braintree;
44

55
use Omnipay\Tests\GatewayTestCase;
6-
use Omnipay\Common\CreditCard;
76

87
class GatewayTest extends GatewayTestCase
98
{
@@ -124,4 +123,56 @@ public function testClientToken()
124123
$request = $this->gateway->clientToken(array());
125124
$this->assertInstanceOf('Omnipay\Braintree\Message\ClientTokenRequest', $request);
126125
}
126+
127+
public function testCreateSubscription()
128+
{
129+
$request = $this->gateway->createSubscription(array());
130+
$this->assertInstanceOf('Omnipay\Braintree\Message\CreateSubscriptionRequest', $request);
131+
}
132+
133+
public function testCancelSubscription()
134+
{
135+
$request = $this->gateway->cancelSubscription('1');
136+
$this->assertInstanceOf('Omnipay\Braintree\Message\CancelSubscriptionRequest', $request);
137+
}
138+
139+
public function testParseNotification()
140+
{
141+
$xml = '<notification></notification>';
142+
$payload = base64_encode($xml);
143+
$signature = \Braintree_Digest::hexDigestSha1(\Braintree_Configuration::privateKey(), $payload);
144+
$gatewayMock = $this->buildGatewayMock($payload);
145+
$gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest(), $gatewayMock);
146+
$params = array(
147+
'bt_signature' => $payload.'|'.$signature,
148+
'bt_payload' => $payload
149+
);
150+
$request = $gateway->parseNotification($params);
151+
$this->assertInstanceOf('\Braintree_WebhookNotification', $request);
152+
}
153+
154+
/**
155+
* @param $payload
156+
*
157+
* @return \Braintree_Gateway
158+
*/
159+
protected function buildGatewayMock($payload)
160+
{
161+
$configuration = $this->getMockBuilder('\Braintree_Configuration')
162+
->disableOriginalConstructor()
163+
->setMethods(array(
164+
'assertHasAccessTokenOrKeys'
165+
))
166+
->getMock();
167+
$configuration->expects($this->any())
168+
->method('assertHasAccessTokenOrKeys')
169+
->will($this->returnValue(null));
170+
171+
172+
173+
$configuration->setPublicKey($payload);
174+
175+
\Braintree_Configuration::$global = $configuration;
176+
return \Braintree_Configuration::gateway();
177+
}
127178
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* This file is part of Rocketgraph service
4+
* <http://www.rocketgraph.com>
5+
*/
6+
7+
namespace Omnipay\Braintree\Message;
8+
use Omnipay\Tests\TestCase;
9+
10+
class CustomerResponseTest extends TestCase
11+
{
12+
/**
13+
* @var CreateCustomerRequest
14+
*/
15+
private $request;
16+
17+
public function setUp()
18+
{
19+
parent::setUp();
20+
21+
$this->request = new CreateCustomerRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway());
22+
}
23+
24+
public function testGetSubscriptionData()
25+
{
26+
$data = new \stdClass();
27+
28+
$response = new CustomerResponse($this->request, $data);
29+
$this->assertNull($response->getCustomerData());
30+
31+
$data->customer = 'customerData';
32+
33+
$response = new CustomerResponse($this->request, $data);
34+
$this->assertEquals('customerData', $response->getCustomerData());
35+
}
36+
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* This file is part of Rocketgraph service
4+
* <http://www.rocketgraph.com>
5+
*/
6+
7+
namespace Omnipay\Braintree\Message;
8+
use Omnipay\Tests\TestCase;
9+
10+
class SubscriptionResponseTest extends TestCase
11+
{
12+
/**
13+
* @var CreateSubscriptionRequest
14+
*/
15+
private $request;
16+
17+
public function setUp()
18+
{
19+
parent::setUp();
20+
21+
$this->request = new CreateSubscriptionRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway());
22+
}
23+
24+
public function testGetSubscriptionData()
25+
{
26+
$data = new \stdClass();
27+
28+
$response = new SubscriptionResponse($this->request, $data);
29+
$this->assertNull($response->getSubscriptionData());
30+
31+
$data->subscription = 'subscriptionData';
32+
33+
$response = new SubscriptionResponse($this->request, $data);
34+
$this->assertEquals('subscriptionData', $response->getSubscriptionData());
35+
}
36+
37+
}

0 commit comments

Comments
 (0)