Skip to content

Commit bd69207

Browse files
committed
Merge pull request #311 from formapro-forks/omnipay-fix-fatal-in-offsite-factory
[omnipay] Fix fatal error when omnipay offsite factory is used.
2 parents 220788c + b0bd91f commit bd69207

File tree

4 files changed

+11
-113
lines changed

4 files changed

+11
-113
lines changed
Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
<?php
22
namespace Payum\Bundle\PayumBundle\DependencyInjection\Factory\Gateway;
33

4-
use Omnipay\Omnipay;
5-
use Payum\Core\Exception\LogicException;
6-
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
7-
84
/**
95
* @deprecated since 1.0.0-BETA2
106
*/
11-
class OmnipayDirectGatewayFactory extends AbstractGatewayFactory
7+
class OmnipayDirectGatewayFactory extends OmnipayGatewayFactory
128
{
139
/**
1410
* {@inheritdoc}
@@ -18,55 +14,11 @@ public function getName()
1814
return 'omnipay_direct';
1915
}
2016

21-
/**
22-
* {@inheritdoc}
23-
*/
24-
public function addConfiguration(ArrayNodeDefinition $builder)
25-
{
26-
parent::addConfiguration($builder);
27-
28-
$builder->children()
29-
->scalarNode('type')->isRequired()->cannotBeEmpty()->end()
30-
->arrayNode('options')->isRequired()
31-
->useAttributeAsKey('key')
32-
->prototype('scalar')->end()
33-
->end()
34-
->end();
35-
36-
$builder
37-
->validate()
38-
->ifTrue(function ($v) {
39-
$gatewayFactory = Omnipay::getFactory();
40-
$gatewayFactory->find();
41-
42-
$supportedTypes = $gatewayFactory->all();
43-
if (false == in_array($v['type'], $supportedTypes) && !class_exists($v['type'])) {
44-
throw new LogicException(sprintf(
45-
'Given type %s is not supported. Try one of supported types: %s or use the gateway full class name.',
46-
$v['type'],
47-
implode(', ', $supportedTypes)
48-
));
49-
}
50-
51-
return false;
52-
})
53-
->thenInvalid('A message')
54-
;
55-
}
56-
5717
/**
5818
* {@inheritDoc}
5919
*/
6020
protected function getPayumGatewayFactoryClass()
6121
{
62-
return 'Payum\OmnipayBridge\OmnipayDirectGatewayFactory';
63-
}
64-
65-
/**
66-
* {@inheritDoc}
67-
*/
68-
protected function getComposerPackage()
69-
{
70-
return 'payum/omnipay-bridge';
22+
return \Payum\OmnipayBridge\OmnipayDirectGatewayFactory::class;
7123
}
7224
}

DependencyInjection/Factory/Gateway/OmnipayOffsiteGatewayFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/**
55
* @deprecated since 1.0.0-BETA2
66
*/
7-
class OmnipayOffsiteGatewayFactory extends OmnipayDirectGatewayFactory
7+
class OmnipayOffsiteGatewayFactory extends OmnipayGatewayFactory
88
{
99
/**
1010
* {@inheritdoc}
@@ -19,6 +19,6 @@ public function getName()
1919
*/
2020
protected function getPayumGatewayFactoryClass()
2121
{
22-
return 'Payum\OmnipayBridge\OmnipayOffsiteGatewayFactory';
22+
return \Payum\OmnipayBridge\OmnipayOffsiteGatewayFactory::class;
2323
}
24-
}
24+
}

Tests/DependencyInjection/Factory/Gateway/OmnipayDirectGatewayFactoryTest.php

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,6 @@ public function thrownIfTypeSectionMissing()
9191
$processor->process($tb->buildTree(), array());
9292
}
9393

94-
/**
95-
* @test
96-
*
97-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
98-
* @expectedExceptionMessage Invalid configuration for path "foo": Given type notSupportedGatewayType is not supported.
99-
*/
100-
public function thrownIfTypeNotSupportedByOmnipay()
101-
{
102-
$factory = new OmnipayDirectGatewayFactory;
103-
104-
$tb = new TreeBuilder();
105-
$rootNode = $tb->root('foo');
106-
107-
$factory->addConfiguration($rootNode);
108-
109-
$processor = new Processor();
110-
$processor->process($tb->buildTree(), array(array(
111-
'type' => 'notSupportedGatewayType',
112-
'options' => array(),
113-
)));
114-
}
115-
11694
/**
11795
* @test
11896
*
@@ -188,16 +166,16 @@ public function shouldLoadFactory()
188166
$factoryService->getTag('payum.gateway_factory')
189167
);
190168

191-
$factoryConfig = $factoryService->getArgument(0);
169+
$factoryConfig = $factoryService->getArgument(2);
192170
$this->assertEquals('omnipay_direct', $factoryConfig['payum.factory_name']);
193171
$this->assertArrayHasKey('payum.http_client', $factoryConfig);
194172
$this->assertArrayHasKey('twig.env', $factoryConfig);
195173
$this->assertArrayHasKey('payum.iso4217', $factoryConfig);
196174
$this->assertArrayHasKey('payum.template.layout', $factoryConfig);
197175
$this->assertArrayHasKey('payum.template.obtain_credit_card', $factoryConfig);
198176

199-
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $factoryService->getArgument(1));
200-
$this->assertEquals('payum.gateway_factory', (string) $factoryService->getArgument(1));
177+
$this->assertInstanceOf(Reference::class, $factoryService->getArgument(3));
178+
$this->assertEquals('payum.gateway_factory', (string) $factoryService->getArgument(3));
201179
}
202180

203181
/**

Tests/DependencyInjection/Factory/Gateway/OmnipayOffsiteGatewayFactoryTest.php

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@
1212

1313
class OmnipayOffsiteGatewayFactoryTest extends \PHPUnit_Framework_TestCase
1414
{
15-
/**
16-
* @test
17-
*/
18-
public function shouldBeSubClassOfOmnipayDirectGatewayFactory()
19-
{
20-
$rc = new \ReflectionClass('Payum\Bundle\PayumBundle\DependencyInjection\Factory\Gateway\OmnipayOffsiteGatewayFactory');
21-
22-
$this->assertTrue($rc->isSubclassOf('Payum\Bundle\PayumBundle\DependencyInjection\Factory\Gateway\OmnipayDirectGatewayFactory'));
23-
}
24-
2515
/**
2616
* @test
2717
*/
@@ -96,28 +86,6 @@ public function thrownIfTypeSectionMissing()
9686
$processor->process($tb->buildTree(), array());
9787
}
9888

99-
/**
100-
* @test
101-
*
102-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
103-
* @expectedExceptionMessage Invalid configuration for path "foo": Given type notSupportedGatewayType is not supported.
104-
*/
105-
public function thrownIfTypeNotSupportedByOmnipay()
106-
{
107-
$factory = new OmnipayOffsiteGatewayFactory;
108-
109-
$tb = new TreeBuilder();
110-
$rootNode = $tb->root('foo');
111-
112-
$factory->addConfiguration($rootNode);
113-
114-
$processor = new Processor();
115-
$processor->process($tb->buildTree(), array(array(
116-
'type' => 'notSupportedGatewayType',
117-
'options' => array()
118-
)));
119-
}
120-
12189
/**
12290
* @test
12391
*
@@ -193,16 +161,16 @@ public function shouldLoadFactory()
193161
$factoryService->getTag('payum.gateway_factory')
194162
);
195163

196-
$factoryConfig = $factoryService->getArgument(0);
164+
$factoryConfig = $factoryService->getArgument(2);
197165
$this->assertEquals('omnipay_offsite', $factoryConfig['payum.factory_name']);
198166
$this->assertArrayHasKey('payum.http_client', $factoryConfig);
199167
$this->assertArrayHasKey('twig.env', $factoryConfig);
200168
$this->assertArrayHasKey('payum.iso4217', $factoryConfig);
201169
$this->assertArrayHasKey('payum.template.layout', $factoryConfig);
202170
$this->assertArrayHasKey('payum.template.obtain_credit_card', $factoryConfig);
203171

204-
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $factoryService->getArgument(1));
205-
$this->assertEquals('payum.gateway_factory', (string) $factoryService->getArgument(1));
172+
$this->assertInstanceOf(Reference::class, $factoryService->getArgument(3));
173+
$this->assertEquals('payum.gateway_factory', (string) $factoryService->getArgument(3));
206174
}
207175

208176
/**

0 commit comments

Comments
 (0)