示例#1
0
 /**
  * @test
  */
 public function shouldCreateGatewayUsingConfigOnGetGateway()
 {
     $gatewayConfig = new GatewayConfig();
     $gatewayConfig->setConfig($config = array('foo' => 'fooVal', 'bar' => 'barVal'));
     $gatewayConfig->setFactoryName($factoryName = 'theFactoryName');
     $gatewayConfig->setGatewayName($gatewayName = 'theGatewayName');
     $gateway = new Gateway();
     $gatewayFactoryMock = $this->getMock('Payum\\Core\\GatewayFactoryInterface');
     $gatewayFactoryMock->expects($this->once())->method('create')->with($config)->willReturn($gateway);
     $staticRegistryMock = $this->createRegistryMock();
     $staticRegistryMock->expects($this->once())->method('getGatewayFactory')->with($factoryName)->willReturn($gatewayFactoryMock);
     $storageMock = $this->createStorageMock();
     $storageMock->expects($this->once())->method('findBy')->with(array('gatewayName' => $gatewayName))->willReturn(array($gatewayConfig));
     $registry = new DynamicRegistry($storageMock, $staticRegistryMock);
     $this->assertSame($gateway, $registry->getGateway($gatewayName));
 }
示例#2
0
 /**
  * @test
  */
 public function shouldCreateGatewayOnlyOnceWhenCalledMultipleTimes()
 {
     $gatewayConfig = new GatewayConfig();
     $gatewayConfig->setConfig($config = array('foo' => 'fooVal', 'bar' => 'barVal'));
     $gatewayConfig->setFactoryName($factoryName = 'theFactoryName');
     $gatewayConfig->setGatewayName($gatewayName = 'theGatewayName');
     $gateway = new Gateway();
     $gatewayFactoryMock = $this->getMock(GatewayFactoryInterface::class);
     $gatewayFactoryMock->expects($this->once())->method('create')->with($config)->willReturn($gateway);
     $gatewayFactoryRegistry = $this->createGatewayFactoryRegistryMock();
     $gatewayFactoryRegistry->expects($this->atLeastOnce())->method('getGatewayFactory')->with($factoryName)->willReturn($gatewayFactoryMock);
     $storageMock = $this->createStorageMock();
     $storageMock->expects($this->atLeastOnce())->method('findBy')->with(array('gatewayName' => $gatewayName))->willReturn(array($gatewayConfig));
     $registry = new DynamicRegistry($storageMock, $gatewayFactoryRegistry);
     $this->assertSame($gateway, $registry->getGateway($gatewayName));
     $this->assertSame($gateway, $registry->getGateway($gatewayName));
 }
示例#3
0
 /**
  * @test
  */
 public function shouldAllowGetPreviouslySetConfig()
 {
     $config = new GatewayConfig();
     $config->setConfig(array('foo' => 'fooVal'));
     $this->assertEquals(array('foo' => 'fooVal'), $config->getConfig());
 }
 /**
  * @test
  */
 public function shouldAddConfigFieldsIfGatewayConfigHasFactorySet()
 {
     $this->fooGatewayFactoryMock->expects($this->once())->method('createConfig')->with(array())->willReturn(array('payum.default_options' => array('username' => 'defaultName', 'password' => 'defaultPass', 'sandbox' => true), 'payum.required_options' => array()));
     $gatewayConfig = new GatewayConfig();
     $gatewayConfig->setFactoryName('foo');
     $gatewayConfig->setGatewayName('theName');
     $gatewayConfig->setConfig(array('username' => 'modelName', 'password' => 'modelPass', 'sandbox' => false));
     $form = $this->formFactory->create(GatewayConfigType::class, $gatewayConfig);
     $this->assertTrue($form->has('config'));
     $this->assertTrue($form->get('config')->has('username'));
     $this->assertEquals('modelName', $form->get('config')->get('username')->getData());
     $this->assertTrue($form->get('config')->has('password'));
     $this->assertEquals('modelPass', $form->get('config')->get('password')->getData());
     $this->assertTrue($form->get('config')->has('sandbox'));
     $this->assertEquals(false, $form->get('config')->get('sandbox')->getData());
 }