|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Sylius\Bundle\CoreBundle\Tests\Fixture; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
17
|
|
|
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; |
|
18
|
|
|
use PHPUnit\Framework\TestCase; |
|
19
|
|
|
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface; |
|
20
|
|
|
use Sylius\Bundle\CoreBundle\Fixture\PaymentMethodFixture; |
|
21
|
|
|
|
|
22
|
|
|
final class PaymentMethodFixtureTest extends TestCase |
|
23
|
|
|
{ |
|
24
|
|
|
use ConfigurationTestCaseTrait; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @test |
|
28
|
|
|
*/ |
|
29
|
|
|
public function payment_methods_are_optional(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->assertConfigurationIsValid([[]], 'custom'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @test |
|
36
|
|
|
*/ |
|
37
|
|
|
public function payment_methods_can_be_generated_randomly(): void |
|
38
|
|
|
{ |
|
39
|
|
|
$this->assertConfigurationIsValid([['random' => 4]], 'random'); |
|
40
|
|
|
$this->assertPartialConfigurationIsInvalid([['random' => -1]], 'random'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @test |
|
45
|
|
|
*/ |
|
46
|
|
|
public function payment_method_code_is_optional(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$this->assertConfigurationIsValid([['custom' => [['code' => 'CUSTOM']]]], 'custom.*.code'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @test |
|
53
|
|
|
*/ |
|
54
|
|
|
public function payment_method_gateway_name_is_optional(): void |
|
55
|
|
|
{ |
|
56
|
|
|
$this->assertConfigurationIsValid([['custom' => [['gatewayName' => 'Online']]]], 'custom.*.gatewayName'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @test |
|
61
|
|
|
*/ |
|
62
|
|
|
public function payment_method_gateway_factory_is_optional(): void |
|
63
|
|
|
{ |
|
64
|
|
|
$this->assertConfigurationIsValid([['custom' => [['gatewayFactory' => 'offline']]]], 'custom.*.gatewayFactory'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @test |
|
69
|
|
|
*/ |
|
70
|
|
|
public function payment_method_gateway_configuration_is_optional(): void |
|
71
|
|
|
{ |
|
72
|
|
|
$this->assertConfigurationIsValid([['custom' => [['gatewayConfig' => []]]]], 'custom.*.gatewayConfig'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @test |
|
77
|
|
|
*/ |
|
78
|
|
|
public function payment_method_instructions_configuration_must_by_string(): void |
|
79
|
|
|
{ |
|
80
|
|
|
$this->assertConfigurationIsValid([['custom' => [['instructions' => 'test']]]], 'custom.*.instructions'); |
|
81
|
|
|
$this->assertConfigurationIsInvalid([['custom' => [['instructions' => ['test']]]]], 'Invalid type for path "payment_method.custom.0.instructions". Expected scalar, but got array'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @test |
|
86
|
|
|
*/ |
|
87
|
|
|
public function payment_method_instructions_configuration_can_be_null(): void |
|
88
|
|
|
{ |
|
89
|
|
|
$this->assertConfigurationIsValid([['custom' => [['instructions' => null]]]], 'custom.*.instructions'); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @test |
|
94
|
|
|
*/ |
|
95
|
|
|
public function payment_method_instructions_configuration_default_null(): void |
|
96
|
|
|
{ |
|
97
|
|
|
$this->assertProcessedConfigurationEquals( |
|
98
|
|
|
[['custom' => [[]]]], |
|
99
|
|
|
['custom' => [[]]], |
|
100
|
|
|
'custom.*.instructions' |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @test |
|
106
|
|
|
*/ |
|
107
|
|
|
public function payment_method_instructions_configuration_is_optional(): void |
|
108
|
|
|
{ |
|
109
|
|
|
$this->assertConfigurationIsValid([['custom' => [[]]]], 'custom.*.instructions'); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @test |
|
114
|
|
|
*/ |
|
115
|
|
|
public function payment_method_gateway_configuration_must_by_array(): void |
|
116
|
|
|
{ |
|
117
|
|
|
$this->assertConfigurationIsValid([['custom' => [['gatewayConfig' => ['username' => 'USERNAME']]]]], 'custom.*.gatewayConfig'); |
|
118
|
|
|
$this->assertConfigurationIsInvalid([['custom' => [['gatewayConfig' => 'USERNAME']]]], 'Invalid type for path "payment_method.custom.0.gatewayConfig". Expected array, but got string'); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @test |
|
123
|
|
|
*/ |
|
124
|
|
|
public function payment_method_may_be_toggled(): void |
|
125
|
|
|
{ |
|
126
|
|
|
$this->assertConfigurationIsValid([['custom' => [['enabled' => false]]]], 'custom.*.enabled'); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* {@inheritdoc} |
|
131
|
|
|
*/ |
|
132
|
|
|
protected function getConfiguration(): PaymentMethodFixture |
|
133
|
|
|
{ |
|
134
|
|
|
return new PaymentMethodFixture( |
|
135
|
|
|
$this->getMockBuilder(ObjectManager::class)->getMock(), |
|
136
|
|
|
$this->getMockBuilder(ExampleFactoryInterface::class)->getMock() |
|
137
|
|
|
); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|