Skip to content

Commit

Permalink
Merge pull request #220 from thephpleague/fix-gateway-params
Browse files Browse the repository at this point in the history
Make set/getParameter public on Gateway
  • Loading branch information
barryvdh authored Jun 2, 2020
2 parents 24ea70a + 9199629 commit 24148b7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
24 changes: 23 additions & 1 deletion src/Common/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
*/
abstract class AbstractGateway implements GatewayInterface
{
use ParametersTrait;
use ParametersTrait {
setParameter as traitSetParameter;
getParameter as traitGetParameter;
}

/**
* @var ClientInterface
Expand Down Expand Up @@ -110,6 +113,25 @@ public function getDefaultParameters()
return array();
}

/**
* @param string $key
* @return mixed
*/
public function getParameter($key)
{
return $this->traitGetParameter($key);
}

/**
* @param string $key
* @param mixed $value
* @return $this
*/
public function setParameter($key, $value)
{
return $this->traitSetParameter($key, $value);
}

/**
* @return boolean
*/
Expand Down
1 change: 1 addition & 0 deletions src/Common/ParametersTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected function setParameter($key, $value)
/**
* Get one parameter.
*
* @param string $key Parameter key
* @return mixed A single parameter value.
*/
protected function getParameter($key)
Expand Down
18 changes: 16 additions & 2 deletions tests/Omnipay/Common/AbstractGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

class AbstractGatewayTest extends TestCase
{
/** @var \Omnipay\Common\AbstractGateway */
protected $gateway;

public function setUp()
{
$this->gateway = m::mock('\Omnipay\Common\AbstractGateway')->makePartial();
$this->gateway = new AbstractGatewayTest_MockAbstractGateway();
$this->gateway->initialize();
}

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

public function testGetShortName()
{
$this->assertSame('\\'.get_class($this->gateway), $this->gateway->getShortName());
$this->assertSame('Common_AbstractGatewayTest_MockAbstract', $this->gateway->getShortName());
}

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

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

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

public function testSetSetParameter()
{
$token = 'foobar';

$this->gateway->setParameter('token', $token);

$this->assertEquals($token, $this->gateway->getParameter('token'));
}

public function testTestMode()
{
$this->assertSame($this->gateway, $this->gateway->setTestMode(true));
Expand Down

0 comments on commit 24148b7

Please sign in to comment.