Open Monograph Press  3.3.0
AbstractGatewayTest.php
1 <?php
2 
3 namespace Omnipay\Common;
4 
5 use Mockery as m;
7 use Omnipay\Tests\TestCase;
9 
10 class AbstractGatewayTest extends TestCase
11 {
12  public function setUp()
13  {
14  $this->gateway = m::mock('\Omnipay\Common\AbstractGateway')->makePartial();
15  $this->gateway->initialize();
16  }
17 
18  public function testConstruct()
19  {
20  $this->gateway = new AbstractGatewayTest_MockAbstractGateway;
21  $this->assertInstanceOf('\Guzzle\Http\Client', $this->gateway->getProtectedHttpClient());
22  $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Request', $this->gateway->getProtectedHttpRequest());
23  $this->assertSame(array(), $this->gateway->getParameters());
24  }
25 
26  public function testGetShortName()
27  {
28  $this->assertSame('\\'.get_class($this->gateway), $this->gateway->getShortName());
29  }
30 
31  public function testInitializeDefaults()
32  {
33  $defaults = array(
34  'currency' => 'AUD', // fixed default type
35  'username' => array('joe', 'fred'), // enum default type
36  );
37  $this->gateway->shouldReceive('getDefaultParameters')->once()
38  ->andReturn($defaults);
39 
40  $this->gateway->initialize();
41 
42  $expected = array(
43  'currency' => 'AUD',
44  'username' => 'joe',
45  );
46  $this->assertSame($expected, $this->gateway->getParameters());
47  }
48 
49  public function testInitializeParameters()
50  {
51  $this->gateway->shouldReceive('getDefaultParameters')->once()
52  ->andReturn(array('currency' => 'AUD'));
53 
54  $this->gateway->initialize(array(
55  'currency' => 'USD',
56  'unknown' => '42',
57  ));
58 
59  $this->assertSame(array('currency' => 'USD'), $this->gateway->getParameters());
60  }
61 
62  public function testGetDefaultParameters()
63  {
64  $this->assertSame(array(), $this->gateway->getDefaultParameters());
65  }
66 
67  public function testGetParameters()
68  {
69  $this->gateway->setTestMode(true);
70 
71  $this->assertSame(array('testMode' => true), $this->gateway->getParameters());
72  }
73 
74  public function testTestMode()
75  {
76  $this->assertSame($this->gateway, $this->gateway->setTestMode(true));
77  $this->assertSame(true, $this->gateway->getTestMode());
78  }
79 
80  public function testCurrency()
81  {
82  $this->assertSame($this->gateway, $this->gateway->setCurrency('USD'));
83  $this->assertSame('USD', $this->gateway->getCurrency());
84  }
85 
86  public function testSupportsAuthorize()
87  {
88  $this->assertFalse($this->gateway->supportsAuthorize());
89  }
90 
92  {
93  $this->assertFalse($this->gateway->supportsCompleteAuthorize());
94  }
95 
96  public function testSupportsCapture()
97  {
98  $this->assertFalse($this->gateway->supportsCapture());
99  }
100 
101  public function testSupportsPurchase()
102  {
103  $this->assertFalse($this->gateway->supportsPurchase());
104  }
105 
107  {
108  $this->assertFalse($this->gateway->supportsCompletePurchase());
109  }
110 
111  public function testSupportsRefund()
112  {
113  $this->assertFalse($this->gateway->supportsRefund());
114  }
115 
116  public function testSupportsVoid()
117  {
118  $this->assertFalse($this->gateway->supportsVoid());
119  }
120 
121  public function testSupportsCreateCard()
122  {
123  $this->assertFalse($this->gateway->supportsCreateCard());
124  }
125 
126  public function testSupportsDeleteCard()
127  {
128  $this->assertFalse($this->gateway->supportsDeleteCard());
129  }
130 
131  public function testSupportsUpdateCard()
132  {
133  $this->assertFalse($this->gateway->supportsUpdateCard());
134  }
135 
137  {
138  $this->assertFalse($this->gateway->supportsAcceptNotification());
139  }
140 
141  public function testCreateRequest()
142  {
143  $this->gateway = new AbstractGatewayTest_MockAbstractGateway;
144  $request = $this->gateway->callCreateRequest(
145  '\Omnipay\Common\AbstractGatewayTest_MockAbstractRequest',
146  array('currency' => 'THB')
147  );
148 
149  $this->assertSame(array('currency' => 'THB'), $request->getParameters());
150  }
151 }
152 
154 {
155  public function getName()
156  {
157  return 'Mock Gateway Implementation';
158  }
159 
160  public function getProtectedHttpClient()
161  {
162  return $this->httpClient;
163  }
164 
165  public function getProtectedHttpRequest()
166  {
167  return $this->httpRequest;
168  }
169 
170  public function callCreateRequest($class, array $parameters)
171  {
172  return $this->createRequest($class, $parameters);
173  }
174 }
175 
177 {
178  public function getData() {}
179  public function sendData($data) {}
180 }
Omnipay\Common\AbstractGatewayTest\testCurrency
testCurrency()
Definition: AbstractGatewayTest.php:80
Omnipay\Common\AbstractGatewayTest\testSupportsCreateCard
testSupportsCreateCard()
Definition: AbstractGatewayTest.php:121
Omnipay\Common\AbstractGatewayTest\testConstruct
testConstruct()
Definition: AbstractGatewayTest.php:18
Omnipay\Common\AbstractGatewayTest_MockAbstractRequest
Definition: AbstractGatewayTest.php:176
Omnipay\Common\Message\AbstractRequest
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:62
Omnipay\Common\AbstractGatewayTest_MockAbstractGateway\getName
getName()
Definition: AbstractGatewayTest.php:155
Omnipay\Common\AbstractGatewayTest_MockAbstractGateway\callCreateRequest
callCreateRequest($class, array $parameters)
Definition: AbstractGatewayTest.php:170
Omnipay\Common\AbstractGatewayTest_MockAbstractRequest\sendData
sendData($data)
Definition: AbstractGatewayTest.php:179
Omnipay\Common\AbstractGatewayTest_MockAbstractRequest\getData
getData()
Definition: AbstractGatewayTest.php:178
Omnipay\Common\AbstractGateway
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/AbstractGateway.php:45
Omnipay\Common\AbstractGatewayTest\testSupportsUpdateCard
testSupportsUpdateCard()
Definition: AbstractGatewayTest.php:131
Omnipay\Common\AbstractGateway\$httpClient
$httpClient
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/AbstractGateway.php:61
Omnipay\Common\AbstractGatewayTest\testSupportsDeleteCard
testSupportsDeleteCard()
Definition: AbstractGatewayTest.php:126
Omnipay\Common\AbstractGatewayTest_MockAbstractGateway\getProtectedHttpClient
getProtectedHttpClient()
Definition: AbstractGatewayTest.php:160
Omnipay\Common\AbstractGateway\createRequest
createRequest($class, array $parameters)
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/AbstractGateway.php:329
Omnipay\Common\AbstractGatewayTest\testGetParameters
testGetParameters()
Definition: AbstractGatewayTest.php:67
Omnipay\Common\AbstractGatewayTest\testSupportsCapture
testSupportsCapture()
Definition: AbstractGatewayTest.php:96
Omnipay\Common\AbstractGatewayTest\testGetDefaultParameters
testGetDefaultParameters()
Definition: AbstractGatewayTest.php:62
Omnipay\Common\AbstractGateway\$httpRequest
$httpRequest
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/AbstractGateway.php:69
Omnipay\Common\AbstractGatewayTest\testSupportsCompleteAuthorize
testSupportsCompleteAuthorize()
Definition: AbstractGatewayTest.php:91
Symfony\Component\HttpFoundation\ParameterBag
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:19
Omnipay\Common\AbstractGatewayTest_MockAbstractGateway
Definition: AbstractGatewayTest.php:153
Omnipay\Common\AbstractGatewayTest\testGetShortName
testGetShortName()
Definition: AbstractGatewayTest.php:26
Omnipay\Common\AbstractGatewayTest\testCreateRequest
testCreateRequest()
Definition: AbstractGatewayTest.php:141
Omnipay\Common\AbstractGatewayTest\testSupportsAcceptNotification
testSupportsAcceptNotification()
Definition: AbstractGatewayTest.php:136
Omnipay\Common\AbstractGatewayTest_MockAbstractGateway\getProtectedHttpRequest
getProtectedHttpRequest()
Definition: AbstractGatewayTest.php:165
Omnipay\Common\AbstractGatewayTest\testSupportsVoid
testSupportsVoid()
Definition: AbstractGatewayTest.php:116
Omnipay\Common\AbstractGatewayTest\testSupportsAuthorize
testSupportsAuthorize()
Definition: AbstractGatewayTest.php:86
Omnipay\Common\AbstractGatewayTest\testInitializeParameters
testInitializeParameters()
Definition: AbstractGatewayTest.php:49
Omnipay\Common
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/AbstractGateway.php:6
Omnipay\Common\AbstractGatewayTest
Definition: AbstractGatewayTest.php:10
Omnipay\Common\AbstractGatewayTest\testSupportsPurchase
testSupportsPurchase()
Definition: AbstractGatewayTest.php:101
Omnipay\Common\AbstractGatewayTest\testInitializeDefaults
testInitializeDefaults()
Definition: AbstractGatewayTest.php:31
Omnipay\Common\AbstractGatewayTest\testSupportsRefund
testSupportsRefund()
Definition: AbstractGatewayTest.php:111
Omnipay\Common\AbstractGatewayTest\setUp
setUp()
Definition: AbstractGatewayTest.php:12
Omnipay\Common\AbstractGatewayTest\testSupportsCompletePurchase
testSupportsCompletePurchase()
Definition: AbstractGatewayTest.php:106
Omnipay\Common\AbstractGateway\$parameters
$parameters
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/AbstractGateway.php:53
Omnipay\Common\AbstractGatewayTest\testTestMode
testTestMode()
Definition: AbstractGatewayTest.php:74