Skip to content

Commit c3c1f36

Browse files
committed
Merge pull request #6 from Dandroas/camel-case-fix
Fixing the camel case setting for getters and setters
2 parents 770815c + 8ecb8d2 commit c3c1f36

File tree

2 files changed

+39
-22
lines changed

2 files changed

+39
-22
lines changed

src/Omnipay/Tests/GatewayTestCase.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public function testDefaultParametersHaveMatchingMethods()
3333
{
3434
$settings = $this->gateway->getDefaultParameters();
3535
foreach ($settings as $key => $default) {
36-
$getter = 'get'.ucfirst($key);
37-
$setter = 'set'.ucfirst($key);
36+
$getter = 'get'.ucfirst($this->camelCase($key));
37+
$setter = 'set'.ucfirst($this->camelCase($key));
3838
$value = uniqid();
3939

4040
$this->assertTrue(method_exists($this->gateway, $getter), "Gateway must implement $getter()");
@@ -187,8 +187,8 @@ public function testAuthorizeParameters()
187187
if ($this->gateway->supportsAuthorize()) {
188188
foreach ($this->gateway->getDefaultParameters() as $key => $default) {
189189
// set property on gateway
190-
$getter = 'get'.ucfirst($key);
191-
$setter = 'set'.ucfirst($key);
190+
$getter = 'get'.ucfirst($this->camelCase($key));
191+
$setter = 'set'.ucfirst($this->camelCase($key));
192192
$value = uniqid();
193193
$this->gateway->$setter($value);
194194

@@ -204,8 +204,8 @@ public function testCompleteAuthorizeParameters()
204204
if ($this->gateway->supportsCompleteAuthorize()) {
205205
foreach ($this->gateway->getDefaultParameters() as $key => $default) {
206206
// set property on gateway
207-
$getter = 'get'.ucfirst($key);
208-
$setter = 'set'.ucfirst($key);
207+
$getter = 'get'.ucfirst($this->camelCase($key));
208+
$setter = 'set'.ucfirst($this->camelCase($key));
209209
$value = uniqid();
210210
$this->gateway->$setter($value);
211211

@@ -221,8 +221,8 @@ public function testCaptureParameters()
221221
if ($this->gateway->supportsCapture()) {
222222
foreach ($this->gateway->getDefaultParameters() as $key => $default) {
223223
// set property on gateway
224-
$getter = 'get'.ucfirst($key);
225-
$setter = 'set'.ucfirst($key);
224+
$getter = 'get'.ucfirst($this->camelCase($key));
225+
$setter = 'set'.ucfirst($this->camelCase($key));
226226
$value = uniqid();
227227
$this->gateway->$setter($value);
228228

@@ -238,8 +238,8 @@ public function testPurchaseParameters()
238238
if ($this->gateway->supportsPurchase()) {
239239
foreach ($this->gateway->getDefaultParameters() as $key => $default) {
240240
// set property on gateway
241-
$getter = 'get'.ucfirst($key);
242-
$setter = 'set'.ucfirst($key);
241+
$getter = 'get'.ucfirst($this->camelCase($key));
242+
$setter = 'set'.ucfirst($this->camelCase($key));
243243
$value = uniqid();
244244
$this->gateway->$setter($value);
245245

@@ -255,8 +255,8 @@ public function testCompletePurchaseParameters()
255255
if ($this->gateway->supportsCompletePurchase()) {
256256
foreach ($this->gateway->getDefaultParameters() as $key => $default) {
257257
// set property on gateway
258-
$getter = 'get'.ucfirst($key);
259-
$setter = 'set'.ucfirst($key);
258+
$getter = 'get'.ucfirst($this->camelCase($key));
259+
$setter = 'set'.ucfirst($this->camelCase($key));
260260
$value = uniqid();
261261
$this->gateway->$setter($value);
262262

@@ -272,8 +272,8 @@ public function testRefundParameters()
272272
if ($this->gateway->supportsRefund()) {
273273
foreach ($this->gateway->getDefaultParameters() as $key => $default) {
274274
// set property on gateway
275-
$getter = 'get'.ucfirst($key);
276-
$setter = 'set'.ucfirst($key);
275+
$getter = 'get'.ucfirst($this->camelCase($key));
276+
$setter = 'set'.ucfirst($this->camelCase($key));
277277
$value = uniqid();
278278
$this->gateway->$setter($value);
279279

@@ -289,8 +289,8 @@ public function testVoidParameters()
289289
if ($this->gateway->supportsVoid()) {
290290
foreach ($this->gateway->getDefaultParameters() as $key => $default) {
291291
// set property on gateway
292-
$getter = 'get'.ucfirst($key);
293-
$setter = 'set'.ucfirst($key);
292+
$getter = 'get'.ucfirst($this->camelCase($key));
293+
$setter = 'set'.ucfirst($this->camelCase($key));
294294
$value = uniqid();
295295
$this->gateway->$setter($value);
296296

@@ -306,8 +306,8 @@ public function testCreateCardParameters()
306306
if ($this->gateway->supportsCreateCard()) {
307307
foreach ($this->gateway->getDefaultParameters() as $key => $default) {
308308
// set property on gateway
309-
$getter = 'get'.ucfirst($key);
310-
$setter = 'set'.ucfirst($key);
309+
$getter = 'get'.ucfirst($this->camelCase($key));
310+
$setter = 'set'.ucfirst($this->camelCase($key));
311311
$value = uniqid();
312312
$this->gateway->$setter($value);
313313

@@ -323,8 +323,8 @@ public function testDeleteCardParameters()
323323
if ($this->gateway->supportsDeleteCard()) {
324324
foreach ($this->gateway->getDefaultParameters() as $key => $default) {
325325
// set property on gateway
326-
$getter = 'get'.ucfirst($key);
327-
$setter = 'set'.ucfirst($key);
326+
$getter = 'get'.ucfirst($this->camelCase($key));
327+
$setter = 'set'.ucfirst($this->camelCase($key));
328328
$value = uniqid();
329329
$this->gateway->$setter($value);
330330

@@ -340,8 +340,8 @@ public function testUpdateCardParameters()
340340
if ($this->gateway->supportsUpdateCard()) {
341341
foreach ($this->gateway->getDefaultParameters() as $key => $default) {
342342
// set property on gateway
343-
$getter = 'get'.ucfirst($key);
344-
$setter = 'set'.ucfirst($key);
343+
$getter = 'get'.ucfirst($this->camelCase($key));
344+
$setter = 'set'.ucfirst($this->camelCase($key));
345345
$value = uniqid();
346346
$this->gateway->$setter($value);
347347

src/Omnipay/Tests/TestCase.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
2424
private $httpClient;
2525
private $httpRequest;
2626

27+
/**
28+
* Converts a string to camel case
29+
*
30+
* @param string $str
31+
* @return string
32+
*/
33+
public function camelCase($str)
34+
{
35+
return preg_replace_callback(
36+
'/_([a-z])/',
37+
function ($match) {
38+
return strtoupper($match[1]);
39+
},
40+
$str
41+
);
42+
}
43+
2744
/**
2845
* Mark a request as being mocked
2946
*

0 commit comments

Comments
 (0)