/**
     * @test
     */
    public function shouldAddPayumMappingIfDoctrineBundleRegisteredAndDbalConfigured()
    {
        $extension = new PayumExtension;

        $container = new ContainerBuilder;
        $container->setParameter('kernel.bundles', array('DoctrineBundle' => 'DoctrineBundle'));

        $container->prependExtensionConfig('doctrine', array());
        $container->prependExtensionConfig('doctrine', array(
            'dbal' => 'not empty'
        ));

        $extension->prepend($container);

        $rc = new \ReflectionClass('Payum\Core\Payment');
        $payumRootDir = dirname($rc->getFileName());

        $this->assertEquals(
            array(
                array(
                    'orm' => array('mappings' => array(
                        'payum' => array(
                            'is_bundle' => false,
                            'type' => 'xml',
                            'dir' => $payumRootDir.'/Bridge/Doctrine/Resources/mapping',
                            'prefix' => 'Payum\Core\Model',
                        )
                    )),
                ),
                array('dbal' => 'not empty'),
                array(),
            ),
            $container->getExtensionConfig('doctrine')
        );
    }
    /**
     * @test
     */
    public function shouldNotConfigureSonataAdminClassForPaymentConfigIfDisabled()
    {
        $config = array(
            'dynamic_payments' => array(
                'sonata_admin' => false,
                'config_storage' => array(
                    'Payum\Bundle\PayumBundle\Tests\Functional\DependencyInjection\TestPaymentConfig' => array(
                        'filesystem' => array(
                            'storage_dir' => sys_get_temp_dir(),
                            'id_property' => 'hash'
                        )
                    )
                )
            ),
            'security' => array(
                'token_storage' => array(
                    'Payum\Core\Model\Token' => array(
                        'filesystem' => array(
                            'storage_dir' => sys_get_temp_dir(),
                            'id_property' => 'hash'
                        )
                    )
                )
            ),
            'payments' => array(),
        );

        $configs = array($config);

        $containerBuilder = new ContainerBuilder();
        $containerBuilder->setParameter('kernel.debug', false);

        $extension = new PayumExtension;
        $extension->addStorageFactory(new FilesystemStorageFactory);

        $extension->load($configs, $containerBuilder);

        $this->assertFalse($containerBuilder->hasDefinition('payum.dynamic_payments.payment_config_admin'));
    }
 /**
  * @test
  */
 public function shouldAddGatewaysToBuilder()
 {
     $extension = new PayumExtension();
     $extension->addStorageFactory(new FeeStorageFactory());
     $container = new ContainerBuilder();
     $container->setParameter('kernel.debug', true);
     $container->setParameter('kernel.bundles', []);
     $extension->load([['security' => array('token_storage' => array('Payum\\Core\\Model\\Token' => array('bar_storage' => ['bar_opt' => 'val']))), 'gateways_v2' => array('a_gateway' => array('foo' => 'fooVal'), 'another_gateway' => array('bar' => 'barVal'))]], $container);
     $this->assertTrue($container->hasDefinition('payum.builder'));
     $builder = $container->getDefinition('payum.builder');
     $calls = $builder->getMethodCalls();
     $this->assertEquals('addGateway', $calls[7][0]);
     $this->assertEquals('a_gateway', $calls[7][1][0]);
     $this->assertEquals(['foo' => 'fooVal'], $calls[7][1][1]);
     $this->assertEquals('addGateway', $calls[8][0]);
     $this->assertEquals('another_gateway', $calls[8][1][0]);
     $this->assertEquals(['bar' => 'barVal'], $calls[8][1][1]);
 }
 /**
  * @test
  */
 public function shouldAddPaymentTagWithCorrectContextAndFactoryNamesSet()
 {
     $config = array('security' => array('token_storage' => array('Payum\\Core\\Model\\Token' => array('filesystem' => array('storage_dir' => sys_get_temp_dir(), 'id_property' => 'hash')))), 'contexts' => array('the_paypal_context' => array('paypal_express_checkout_nvp' => array('username' => 'a_username', 'password' => 'a_password', 'signature' => 'a_signature', 'sandbox' => true))));
     $configs = array($config);
     $containerBuilder = new ContainerBuilder(new ParameterBag());
     $extension = new PayumExtension();
     $extension->addPaymentFactory(new PaypalExpressCheckoutNvpPaymentFactory());
     $extension->addStorageFactory(new FilesystemStorageFactory());
     $extension->load($configs, $containerBuilder);
     $paymentDefinition = $containerBuilder->getDefinition('payum.context.the_paypal_context.payment');
     $tagAttributes = $paymentDefinition->getTag('payum.payment');
     $this->assertCount(1, $tagAttributes);
     $attributes = $tagAttributes[0];
     $this->assertArrayHasKey('factory', $attributes);
     $this->assertEquals('paypal_express_checkout_nvp', $attributes['factory']);
     $this->assertArrayHasKey('context', $attributes);
     $this->assertEquals('the_paypal_context', $attributes['context']);
 }
 /**
  * @test
  */
 public function shouldPassContainerToPaymentFactoryPrependMethodIfImplementsPrependFactoryInterface()
 {
     $this->markTestSkipped('The logic was disabled because of the bug. See https://github.com/symfony/symfony/pull/9719');
     $container = new ContainerBuilder();
     $factoryMock = $this->getMock('Payum\\Bundle\\PayumBundle\\Tests\\DependencyInjection\\FactoryPlusPrependExtension');
     $factoryMock->expects($this->any())->method('getName')->will($this->returnValue('aFactory'));
     $factoryMock->expects($this->any())->method('prepend')->with($this->identicalTo($container))->will($this->returnCallback(function (ContainerBuilder $container) {
         $container->prependExtensionConfig('twig', array('foo' => 'fooVal'));
         $container->prependExtensionConfig('twig', array('bar' => 'barVal'));
     }));
     //guard
     $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Extension\\PrependExtensionInterface', $factoryMock);
     $extension = new PayumExtension();
     $extension->addPaymentFactory($factoryMock);
     $extension->prepend($container);
     $this->assertEquals(array(array('bar' => 'barVal'), array('foo' => 'fooVal')), $container->getExtensionConfig('twig'));
 }