|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace PTS\Paysera\Tests; |
|
5
|
|
|
|
|
6
|
|
|
use Payum\Core\Exception\LogicException; |
|
7
|
|
|
use Payum\Core\Gateway; |
|
8
|
|
|
use Payum\Core\GatewayFactoryInterface; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
use PTS\Paysera\PayseraGatewayFactory; |
|
11
|
|
|
|
|
12
|
|
|
class PayseraGatewayFactoryTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @test |
|
16
|
|
|
*/ |
|
17
|
|
|
public function shouldImplementGatewayFactoryInterface() |
|
18
|
|
|
{ |
|
19
|
|
|
$rc = new \ReflectionClass(PayseraGatewayFactory::class); |
|
20
|
|
|
$this->assertTrue($rc->implementsInterface(GatewayFactoryInterface::class)); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @test |
|
25
|
|
|
*/ |
|
26
|
|
|
public function couldBeConstructedWithoutAnyArguments() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->expectNotToPerformAssertions(); |
|
29
|
|
|
new PayseraGatewayFactory(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @test |
|
35
|
|
|
*/ |
|
36
|
|
|
public function shouldUseCoreGatewayFactoryPassedAsSecondArgument() |
|
37
|
|
|
{ |
|
38
|
|
|
$coreGatewayFactory = $this->createMock('Payum\Core\GatewayFactoryInterface'); |
|
39
|
|
|
$factory = new PayseraGatewayFactory([], $coreGatewayFactory); |
|
40
|
|
|
$this->assertAttributeSame($coreGatewayFactory, 'coreGatewayFactory', $factory); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @test |
|
45
|
|
|
*/ |
|
46
|
|
|
public function shouldAllowCreateGateway() |
|
47
|
|
|
{ |
|
48
|
|
|
$factory = new PayseraGatewayFactory(); |
|
49
|
|
|
$gateway = $factory->create([ |
|
50
|
|
|
'projectid' => 'testProjectId', |
|
51
|
|
|
'sign_password' => 'testSignPassword' |
|
52
|
|
|
]); |
|
53
|
|
|
$this->assertInstanceOf(Gateway::class, $gateway); |
|
54
|
|
|
$this->assertAttributeNotEmpty('apis', $gateway); |
|
|
|
|
|
|
55
|
|
|
$this->assertAttributeNotEmpty('actions', $gateway); |
|
|
|
|
|
|
56
|
|
|
$extensions = $this->readAttribute($gateway, 'extensions'); |
|
|
|
|
|
|
57
|
|
|
$this->assertAttributeNotEmpty('extensions', $extensions); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @test |
|
62
|
|
|
*/ |
|
63
|
|
|
public function shouldAllowCreateGatewayWithCustomApi() |
|
64
|
|
|
{ |
|
65
|
|
|
$factory = new PayseraGatewayFactory(); |
|
66
|
|
|
$gateway = $factory->create(['payum.api' => new \stdClass()]); |
|
67
|
|
|
$this->assertInstanceOf(Gateway::class, $gateway); |
|
68
|
|
|
$this->assertAttributeNotEmpty('apis', $gateway); |
|
|
|
|
|
|
69
|
|
|
$this->assertAttributeNotEmpty('actions', $gateway); |
|
|
|
|
|
|
70
|
|
|
$extensions = $this->readAttribute($gateway, 'extensions'); |
|
|
|
|
|
|
71
|
|
|
$this->assertAttributeNotEmpty('extensions', $extensions); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @test |
|
76
|
|
|
*/ |
|
77
|
|
|
public function shouldAllowCreateGatewayConfig() |
|
78
|
|
|
{ |
|
79
|
|
|
$factory = new PayseraGatewayFactory(); |
|
80
|
|
|
$config = $factory->createConfig(); |
|
81
|
|
|
$this->assertInternalType('array', $config); |
|
|
|
|
|
|
82
|
|
|
$this->assertNotEmpty($config); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @test |
|
87
|
|
|
*/ |
|
88
|
|
|
public function shouldAddDefaultConfigPassedInConstructorWhileCreatingGatewayConfig() |
|
89
|
|
|
{ |
|
90
|
|
|
$factory = new PayseraGatewayFactory(array( |
|
91
|
|
|
'foo' => 'fooVal', |
|
92
|
|
|
'bar' => 'barVal', |
|
93
|
|
|
)); |
|
94
|
|
|
$config = $factory->createConfig(); |
|
95
|
|
|
$this->assertInternalType('array', $config); |
|
|
|
|
|
|
96
|
|
|
$this->assertArrayHasKey('foo', $config); |
|
97
|
|
|
$this->assertEquals('fooVal', $config['foo']); |
|
98
|
|
|
$this->assertArrayHasKey('bar', $config); |
|
99
|
|
|
$this->assertEquals('barVal', $config['bar']); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @test |
|
104
|
|
|
*/ |
|
105
|
|
|
public function shouldConfigContainDefaultOptions() |
|
106
|
|
|
{ |
|
107
|
|
|
$factory = new PayseraGatewayFactory(); |
|
108
|
|
|
$config = $factory->createConfig(); |
|
109
|
|
|
$this->assertInternalType('array', $config); |
|
|
|
|
|
|
110
|
|
|
$this->assertArrayHasKey('payum.default_options', $config); |
|
111
|
|
|
$this->assertArraySubset( |
|
|
|
|
|
|
112
|
|
|
[ |
|
113
|
|
|
'projectid' => '', |
|
114
|
|
|
'sign_password' => '', |
|
115
|
|
|
'test' => true |
|
116
|
|
|
], |
|
117
|
|
|
$config['payum.default_options'] |
|
118
|
|
|
); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @test |
|
123
|
|
|
*/ |
|
124
|
|
|
public function shouldConfigContainFactoryNameAndTitle() |
|
125
|
|
|
{ |
|
126
|
|
|
$factory = new PayseraGatewayFactory(); |
|
127
|
|
|
$config = $factory->createConfig(); |
|
128
|
|
|
$this->assertInternalType('array', $config); |
|
|
|
|
|
|
129
|
|
|
$this->assertArrayHasKey('payum.factory_name', $config); |
|
130
|
|
|
$this->assertEquals('paysera', $config['payum.factory_name']); |
|
131
|
|
|
$this->assertArrayHasKey('payum.factory_title', $config); |
|
132
|
|
|
$this->assertEquals('paysera', $config['payum.factory_title']); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @test |
|
137
|
|
|
*/ |
|
138
|
|
|
public function shouldThrowIfRequiredOptionsNotPassed() |
|
139
|
|
|
{ |
|
140
|
|
|
$this->expectException(LogicException::class); |
|
141
|
|
|
$this->expectExceptionMessage('The projectid, sign_password fields are required.'); |
|
142
|
|
|
$factory = new PayseraGatewayFactory(); |
|
143
|
|
|
$factory->create(); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @test |
|
148
|
|
|
*/ |
|
149
|
|
|
public function shouldConfigurePaths() |
|
150
|
|
|
{ |
|
151
|
|
|
$factory = new PayseraGatewayFactory(); |
|
152
|
|
|
$config = $factory->createConfig(); |
|
153
|
|
|
$this->assertInternalType('array', $config); |
|
|
|
|
|
|
154
|
|
|
$this->assertNotEmpty($config); |
|
155
|
|
|
$this->assertInternalType('array', $config['payum.paths']); |
|
|
|
|
|
|
156
|
|
|
$this->assertNotEmpty($config['payum.paths']); |
|
157
|
|
|
$this->assertArrayHasKey('PayumCore', $config['payum.paths']); |
|
158
|
|
|
$this->assertStringEndsWith('Resources/views', $config['payum.paths']['PayumCore']); |
|
159
|
|
|
$this->assertTrue(file_exists($config['payum.paths']['PayumCore'])); |
|
160
|
|
|
} |
|
161
|
|
|
} |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.