|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\MagentoBundle\Tests\Unit\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use OroCRM\Bundle\MagentoBundle\DependencyInjection\OroCRMMagentoExtension; |
|
6
|
|
|
use OroCRM\Bundle\MagentoBundle\DependencyInjection\Configuration; |
|
7
|
|
|
|
|
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
9
|
|
|
|
|
10
|
|
|
class OroCRMMagentoExtensionTest extends \PHPUnit_Framework_TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
public function testConfigPassedToConnectors() |
|
13
|
|
|
{ |
|
14
|
|
|
$config = [ |
|
15
|
|
|
'sync_settings' => [ |
|
16
|
|
|
'mistiming_assumption_interval' => '10 minutes', |
|
17
|
|
|
'initial_import_step_interval' => '1 day', |
|
18
|
|
|
'region_sync_interval' => '1 day', |
|
19
|
|
|
'skip_ssl_verification' => false |
|
20
|
|
|
] |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
$container = new ContainerBuilder(); |
|
24
|
|
|
$extension = new OroCRMMagentoExtension(); |
|
25
|
|
|
|
|
26
|
|
|
$extension->load(['oro_crm_magento' => $config], $container); |
|
27
|
|
|
|
|
28
|
|
|
$tagged = $container->findTaggedServiceIds('orocrm_magento.bundle_config.aware'); |
|
29
|
|
|
|
|
30
|
|
|
$missedConfigDefinitions = []; |
|
31
|
|
|
foreach (array_keys($tagged) as $serviceId) { |
|
32
|
|
|
$definition = $container->getDefinition($serviceId); |
|
33
|
|
|
|
|
34
|
|
|
$definition->getArguments(); |
|
|
|
|
|
|
35
|
|
|
$configArguments = array_filter( |
|
36
|
|
|
$definition->getArguments(), |
|
37
|
|
|
function ($arg) use ($config) { |
|
38
|
|
|
return $arg === $config; |
|
39
|
|
|
} |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
if (!$configArguments) { |
|
|
|
|
|
|
43
|
|
|
$missedConfigDefinitions[] = $serviceId; |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$this->assertEquals([], $missedConfigDefinitions, 'Should contain config array'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
|
52
|
|
|
* @expectedExceptionMessage Strategy configuration contains unknown fields "unknown_field" |
|
53
|
|
|
*/ |
|
54
|
|
|
public function testInvalidAccountDiscoveryConfiguration() |
|
55
|
|
|
{ |
|
56
|
|
|
$config = [ |
|
57
|
|
|
[ |
|
58
|
|
|
'account_discovery' => [ |
|
59
|
|
|
'fields' => [ |
|
60
|
|
|
'field1' => null, |
|
61
|
|
|
'field2' => [ |
|
62
|
|
|
'field2.1' => null |
|
63
|
|
|
] |
|
64
|
|
|
], |
|
65
|
|
|
'strategy' => [ |
|
66
|
|
|
'field1' => 'some', |
|
67
|
|
|
'unknown_field' => 'other' |
|
68
|
|
|
] |
|
69
|
|
|
] |
|
70
|
|
|
], |
|
71
|
|
|
null |
|
72
|
|
|
]; |
|
73
|
|
|
$container = new ContainerBuilder(); |
|
74
|
|
|
$extension = new OroCRMMagentoExtension(); |
|
75
|
|
|
$extension->load($config, $container); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @dataProvider inheritanceConfigurationDataProvider |
|
80
|
|
|
* |
|
81
|
|
|
* @param array $config |
|
82
|
|
|
* @param array $resultConfig |
|
83
|
|
|
*/ |
|
84
|
|
|
public function testInheritanceConfiguration(array $config, array $resultConfig) |
|
85
|
|
|
{ |
|
86
|
|
|
$container = new ContainerBuilder(); |
|
87
|
|
|
$extension = new OroCRMMagentoExtension(); |
|
88
|
|
|
$extension->load($config, $container); |
|
89
|
|
|
$services = $container->findTaggedServiceIds('orocrm_magento.bundle_config.aware'); |
|
90
|
|
|
foreach ($services as $serviceId => $tagAttributes) { |
|
91
|
|
|
$tagAttributes = reset($tagAttributes); |
|
92
|
|
|
if (isset($tagAttributes['argument_number'])) { |
|
93
|
|
|
$serviceDefinition = $container->getDefinition($serviceId); |
|
94
|
|
|
$serviceArgument = $serviceDefinition->getArgument($tagAttributes['argument_number']); |
|
95
|
|
|
self::assertArrayHasKey(Configuration::DISCOVERY_NODE, $serviceArgument); |
|
96
|
|
|
self::assertArrayHasKey( |
|
97
|
|
|
Configuration::DISCOVERY_OPTIONS_KEY, |
|
98
|
|
|
$serviceArgument[Configuration::DISCOVERY_NODE] |
|
99
|
|
|
); |
|
100
|
|
|
self::assertArrayHasKey( |
|
101
|
|
|
Configuration::DISCOVERY_STRATEGY_KEY, |
|
102
|
|
|
$serviceArgument[Configuration::DISCOVERY_NODE] |
|
103
|
|
|
); |
|
104
|
|
|
self::assertArrayHasKey( |
|
105
|
|
|
Configuration::DISCOVERY_FIELDS_KEY, |
|
106
|
|
|
$serviceArgument[Configuration::DISCOVERY_NODE] |
|
107
|
|
|
); |
|
108
|
|
|
self::assertEquals( |
|
109
|
|
|
$serviceArgument[Configuration::DISCOVERY_NODE], |
|
110
|
|
|
$resultConfig[Configuration::DISCOVERY_NODE] |
|
111
|
|
|
); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return array |
|
118
|
|
|
*/ |
|
119
|
|
|
public function inheritanceConfigurationDataProvider() |
|
120
|
|
|
{ |
|
121
|
|
|
return [ |
|
122
|
|
|
'one config block' => [ |
|
123
|
|
|
'config' => [ |
|
124
|
|
|
[ |
|
125
|
|
|
'account_discovery' => [ |
|
126
|
|
|
'fields' => ['field1' => null, 'field2' => null, 'field3' => null,], |
|
127
|
|
|
'options' => ['match' => 'first', 'empty' => false,] |
|
128
|
|
|
] |
|
129
|
|
|
], |
|
130
|
|
|
null, |
|
131
|
|
|
], |
|
132
|
|
|
'resultConfig' => [ |
|
133
|
|
|
'account_discovery' => [ |
|
134
|
|
|
'fields' => ['field1' => null, 'field2' => null, 'field3' => null,], |
|
135
|
|
|
'options' => ['match' => 'first', 'empty' => false,], |
|
136
|
|
|
'strategy' => [] |
|
137
|
|
|
] |
|
138
|
|
|
] |
|
139
|
|
|
], |
|
140
|
|
|
'two config block' => [ |
|
141
|
|
|
'config' => [ |
|
142
|
|
|
[ |
|
143
|
|
|
'account_discovery' => [ |
|
144
|
|
|
'fields' => ['field1' => null, 'field2' => null, 'field3' => null], |
|
145
|
|
|
'options' => ['match' => 'first', 'empty' => false] |
|
146
|
|
|
] |
|
147
|
|
|
], |
|
148
|
|
|
[ |
|
149
|
|
|
'account_discovery' => [ |
|
150
|
|
|
'fields' => ['field1' => null], |
|
151
|
|
|
'options' => ['match' => 'first', 'empty' => false] |
|
152
|
|
|
] |
|
153
|
|
|
], |
|
154
|
|
|
null, |
|
155
|
|
|
], |
|
156
|
|
|
'resultConfig' => [ |
|
157
|
|
|
'account_discovery' => [ |
|
158
|
|
|
'fields' => ['field1' => null,], |
|
159
|
|
|
'options' => ['match' => 'first', 'empty' => false,], |
|
160
|
|
|
'strategy' => [] |
|
161
|
|
|
] |
|
162
|
|
|
] |
|
163
|
|
|
], |
|
164
|
|
|
]; |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: