Skip to content

Commit 24148b7

Browse files
authored
Merge pull request thephpleague#220 from thephpleague/fix-gateway-params
Make set/getParameter public on Gateway
2 parents 24ea70a + 9199629 commit 24148b7

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

src/Common/AbstractGateway.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@
4343
*/
4444
abstract class AbstractGateway implements GatewayInterface
4545
{
46-
use ParametersTrait;
46+
use ParametersTrait {
47+
setParameter as traitSetParameter;
48+
getParameter as traitGetParameter;
49+
}
4750

4851
/**
4952
* @var ClientInterface
@@ -110,6 +113,25 @@ public function getDefaultParameters()
110113
return array();
111114
}
112115

116+
/**
117+
* @param string $key
118+
* @return mixed
119+
*/
120+
public function getParameter($key)
121+
{
122+
return $this->traitGetParameter($key);
123+
}
124+
125+
/**
126+
* @param string $key
127+
* @param mixed $value
128+
* @return $this
129+
*/
130+
public function setParameter($key, $value)
131+
{
132+
return $this->traitSetParameter($key, $value);
133+
}
134+
113135
/**
114136
* @return boolean
115137
*/

src/Common/ParametersTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ protected function setParameter($key, $value)
3131
/**
3232
* Get one parameter.
3333
*
34+
* @param string $key Parameter key
3435
* @return mixed A single parameter value.
3536
*/
3637
protected function getParameter($key)

tests/Omnipay/Common/AbstractGatewayTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111
class AbstractGatewayTest extends TestCase
1212
{
13+
/** @var \Omnipay\Common\AbstractGateway */
14+
protected $gateway;
15+
1316
public function setUp()
1417
{
15-
$this->gateway = m::mock('\Omnipay\Common\AbstractGateway')->makePartial();
18+
$this->gateway = new AbstractGatewayTest_MockAbstractGateway();
1619
$this->gateway->initialize();
1720
}
1821

@@ -26,11 +29,12 @@ public function testConstruct()
2629

2730
public function testGetShortName()
2831
{
29-
$this->assertSame('\\'.get_class($this->gateway), $this->gateway->getShortName());
32+
$this->assertSame('Common_AbstractGatewayTest_MockAbstract', $this->gateway->getShortName());
3033
}
3134

3235
public function testInitializeDefaults()
3336
{
37+
$this->gateway = m::mock('\Omnipay\Common\AbstractGateway')->makePartial();
3438
$defaults = array(
3539
'currency' => 'AUD', // fixed default type
3640
'username' => array('joe', 'fred'), // enum default type
@@ -49,6 +53,7 @@ public function testInitializeDefaults()
4953

5054
public function testInitializeParameters()
5155
{
56+
$this->gateway = m::mock('\Omnipay\Common\AbstractGateway')->makePartial();
5257
$this->gateway->shouldReceive('getDefaultParameters')->once()
5358
->andReturn(array('currency' => 'AUD'));
5459

@@ -72,6 +77,15 @@ public function testGetParameters()
7277
$this->assertSame(array('testMode' => true), $this->gateway->getParameters());
7378
}
7479

80+
public function testSetSetParameter()
81+
{
82+
$token = 'foobar';
83+
84+
$this->gateway->setParameter('token', $token);
85+
86+
$this->assertEquals($token, $this->gateway->getParameter('token'));
87+
}
88+
7589
public function testTestMode()
7690
{
7791
$this->assertSame($this->gateway, $this->gateway->setTestMode(true));

0 commit comments

Comments
 (0)