Esempio n. 1
0
 /**
  * @test
  *
  * @dataProvider provideGateways
  */
 public function shouldLoadExtensionWithGateway($config, GatewayFactoryInterface $gatewayFactory)
 {
     $config = array('security' => array('token_storage' => array('Payum\\Core\\Model\\Token' => array('filesystem' => array('storage_dir' => sys_get_temp_dir(), 'id_property' => 'hash')))), 'gateways' => array('a_gateway' => array($gatewayFactory->getName() => $config)));
     $configs = array($config);
     $container = new ContainerBuilder();
     $container->setParameter('kernel.debug', false);
     $extension = new PayumExtension();
     $extension->addGatewayFactory($gatewayFactory);
     $extension->addStorageFactory(new FilesystemStorageFactory());
     $extension->load($configs, $container);
     $this->assertTrue($container->hasDefinition('payum.' . $gatewayFactory->getName() . '.factory'));
     $this->assertTrue($container->hasDefinition('payum.' . $gatewayFactory->getName() . '.a_gateway.gateway'));
     $this->assertEquals('payum.' . $gatewayFactory->getName() . '.factory', $container->getDefinition('payum.' . $gatewayFactory->getName() . '.a_gateway.gateway')->getFactoryService());
     $this->assertEquals('create', $container->getDefinition('payum.' . $gatewayFactory->getName() . '.a_gateway.gateway')->getFactoryMethod());
 }
 /**
  * @test
  *
  * @dataProvider provideGateways
  */
 public function shouldLoadExtensionWithGateway($config, GatewayFactoryInterface $gatewayFactory)
 {
     $config = array('security' => array('token_storage' => array('Payum\\Core\\Model\\Token' => array('filesystem' => array('storage_dir' => sys_get_temp_dir(), 'id_property' => 'hash')))), 'gateways' => array('a_gateway' => array($gatewayFactory->getName() => $config)));
     $configs = array($config);
     $container = new ContainerBuilder();
     $container->setParameter('kernel.debug', false);
     $extension = new PayumExtension();
     $extension->addGatewayFactory($gatewayFactory);
     $extension->addStorageFactory(new FilesystemStorageFactory());
     $extension->load($configs, $container);
     $this->assertTrue($container->hasDefinition('payum.' . $gatewayFactory->getName() . '.factory'));
     $this->assertTrue($container->hasDefinition('payum.' . $gatewayFactory->getName() . '.a_gateway.gateway'));
     $factory = $container->getDefinition('payum.' . $gatewayFactory->getName() . '.a_gateway.gateway')->getFactory();
     $this->assertNotEmpty($factory);
     $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $factory[0]);
     $this->assertEquals('payum.' . $gatewayFactory->getName() . '.factory', (string) $factory[0]);
     $this->assertEquals('create', $factory[1]);
 }
 /**
  * @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());
 }
Esempio n. 4
0
 /**
  * @param GatewayFactoryInterface $factory
  *
  * @throws \Payum\Core\Exception\InvalidArgumentException
  */
 public function addGatewayFactory(GatewayFactoryInterface $factory)
 {
     $factoryName = $factory->getName();
     if (empty($factoryName)) {
         throw new InvalidArgumentException(sprintf('The gateway factory %s has empty name', get_class($factory)));
     }
     if (isset($this->gatewaysFactories[$factoryName])) {
         throw new InvalidArgumentException(sprintf('The gateway factory with such name %s already registered', $factoryName));
     }
     $this->gatewaysFactories[$factory->getName()] = $factory;
 }