-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
namespace Payum\Core\Bridge\Symfony\Builder; | ||
|
||
use Payum\Core\GatewayFactoryInterface; | ||
|
||
class GatewayFactoryBuilder | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $gatewayFactoryClass; | ||
|
||
/** | ||
* @param string $gatewayFactoryClass | ||
*/ | ||
public function __construct($gatewayFactoryClass) | ||
{ | ||
$this->gatewayFactoryClass = $gatewayFactoryClass; | ||
} | ||
|
||
/** | ||
* @param array $defaultConfig | ||
* @param GatewayFactoryInterface $coreGatewayFactory | ||
* | ||
* @return GatewayFactoryInterface | ||
*/ | ||
public function build(array $defaultConfig, GatewayFactoryInterface $coreGatewayFactory) | ||
{ | ||
$gatewayFactoryClass = $this->gatewayFactoryClass; | ||
|
||
return new $gatewayFactoryClass($defaultConfig, $coreGatewayFactory); | ||
} | ||
|
||
public function __invoke() | ||
{ | ||
return call_user_func_array([$this, 'build'], func_get_args()); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
Tests/Bridge/Symfony/Builder/GatewayFactoryBuilderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
namespace Payum\Core\Tests\Bridge\Symfony\Builder; | ||
|
||
use Payum\Core\Bridge\Symfony\Builder\GatewayFactoryBuilder; | ||
use Payum\Core\GatewayFactory; | ||
use Payum\Core\GatewayFactoryInterface; | ||
|
||
class GatewayFactoryBuilderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testCouldBeConstructedWithGatewayFactoryClassAsFirstArgument() | ||
{ | ||
new GatewayFactoryBuilder(GatewayFactory::class); | ||
} | ||
|
||
public function testShouldBuildContainerAwareCoreGatewayFactory() | ||
{ | ||
/** @var GatewayFactoryInterface $coreGatewayFactory */ | ||
$coreGatewayFactory = $this->getMock(GatewayFactoryInterface::class); | ||
$defaultConfig = ['foo' => 'fooVal']; | ||
|
||
$builder = new GatewayFactoryBuilder(GatewayFactory::class); | ||
|
||
$gatewayFactory = $builder->build($defaultConfig, $coreGatewayFactory); | ||
|
||
$this->assertInstanceOf(GatewayFactory::class, $gatewayFactory); | ||
$this->assertAttributeSame($coreGatewayFactory, 'coreGatewayFactory', $gatewayFactory); | ||
$this->assertAttributeSame($defaultConfig, 'defaultConfig', $gatewayFactory); | ||
} | ||
|
||
public function testAllowUseBuilderAsAsFunction() | ||
{ | ||
/** @var GatewayFactoryInterface $coreGatewayFactory */ | ||
$coreGatewayFactory = $this->getMock(GatewayFactoryInterface::class); | ||
$defaultConfig = ['foo' => 'fooVal']; | ||
|
||
$builder = new GatewayFactoryBuilder(GatewayFactory::class); | ||
|
||
$gatewayFactory = $builder($defaultConfig, $coreGatewayFactory); | ||
|
||
$this->assertInstanceOf(GatewayFactory::class, $gatewayFactory); | ||
$this->assertAttributeSame($coreGatewayFactory, 'coreGatewayFactory', $gatewayFactory); | ||
$this->assertAttributeSame($defaultConfig, 'defaultConfig', $gatewayFactory); | ||
} | ||
} |