Skip to content

Commit f33f923

Browse files
committed
Merge remote-tracking branch 'tango-ce/MAGETWO-59641' into MAGETWO-60347
2 parents 8bde202 + acd8edf commit f33f923

File tree

2 files changed

+102
-5
lines changed

2 files changed

+102
-5
lines changed

lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22
/**
3-
*
43
* Copyright © 2016 Magento. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
namespace Magento\Framework\ObjectManager\Config;
87

8+
use Magento\Framework\ObjectManager\ConfigInterface;
99
use Magento\Framework\ObjectManager\ConfigCacheInterface;
1010
use Magento\Framework\ObjectManager\RelationsInterface;
1111

12-
class Compiled implements \Magento\Framework\ObjectManager\ConfigInterface
12+
class Compiled implements ConfigInterface
1313
{
1414
/**
1515
* @var array
@@ -129,9 +129,15 @@ public function getPreference($type)
129129
*/
130130
public function extend(array $configuration)
131131
{
132-
$this->arguments = $configuration['arguments'];
133-
$this->virtualTypes = $configuration['instanceTypes'];
134-
$this->preferences = $configuration['preferences'];
132+
$this->arguments = isset($configuration['arguments'])
133+
? array_replace($this->arguments, $configuration['arguments'])
134+
: $this->arguments;
135+
$this->virtualTypes = isset($configuration['instanceTypes'])
136+
? array_replace($this->virtualTypes, $configuration['instanceTypes'])
137+
: $this->virtualTypes;
138+
$this->preferences = isset($configuration['preferences'])
139+
? array_replace($this->preferences, $configuration['preferences'])
140+
: $this->preferences;
135141
}
136142

137143
/**
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Test\Unit\ObjectManager\Config;
7+
8+
use Magento\Framework\ObjectManager\Config\Compiled as CompiledConfig;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
10+
11+
class CompiledTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var ObjectManagerHelper
15+
*/
16+
private $objectManagerHelper;
17+
18+
protected function setUp()
19+
{
20+
$this->objectManagerHelper = new ObjectManagerHelper($this);
21+
}
22+
23+
/**
24+
* @param array $initialData
25+
* @param array $configuration
26+
* @param array $expectedArguments
27+
* @param array $expectedVirtualTypes
28+
* @param array $expectedPreferences
29+
*
30+
* @dataProvider extendDataProvider
31+
*/
32+
public function testExtend(
33+
array $initialData,
34+
array $configuration,
35+
array $expectedArguments,
36+
array $expectedVirtualTypes,
37+
array $expectedPreferences
38+
) {
39+
/** @var CompiledConfig $compiledConfig */
40+
$compiledConfig = $this->objectManagerHelper->getObject(CompiledConfig::class, ['data' => $initialData]);
41+
$compiledConfig->extend($configuration);
42+
43+
foreach ($expectedArguments as $type => $arguments) {
44+
$this->assertEquals($arguments, $compiledConfig->getArguments($type));
45+
}
46+
47+
$this->assertEquals($expectedVirtualTypes, $compiledConfig->getVirtualTypes());
48+
$this->assertEquals($expectedPreferences, $compiledConfig->getPreferences());
49+
}
50+
51+
/**
52+
* @return array
53+
*/
54+
public function extendDataProvider()
55+
{
56+
return [
57+
[
58+
'initialData' => [
59+
'arguments' => [
60+
'type1' => serialize(['argument1_1' => 'argumentValue1_1', 'argument1_2' => 'argumentValue1_2'])
61+
],
62+
'instanceTypes' => [
63+
'instanceType1' => 'instanceTypeValue1', 'instanceType2' => 'instanceTypeValue2'
64+
],
65+
'preferences' => ['preference1' => 'preferenceValue1', 'preference2' => 'preferenceValue2']
66+
],
67+
'configuration' => [
68+
'arguments' => [
69+
'type1' => serialize(['argument1_1' => 'newArgumentValue1_1']),
70+
'type2' => serialize(['argument2_1' => 'newArgumentValue2_1'])
71+
],
72+
'instanceTypes' => [
73+
'instanceType2' => 'newInstanceTypeValue2', 'instanceType3' => 'newInstanceTypeValue3'
74+
],
75+
'preferences' => ['preference1' => 'newPreferenceValue1']
76+
],
77+
'expectedArguments' => [
78+
'type1' => ['argument1_1' => 'newArgumentValue1_1'],
79+
'type2' => ['argument2_1' => 'newArgumentValue2_1']
80+
],
81+
'expectedVirtualTypes' => [
82+
'instanceType1' => 'instanceTypeValue1', 'instanceType2' => 'newInstanceTypeValue2',
83+
'instanceType3' => 'newInstanceTypeValue3'
84+
],
85+
'expectedPreferences' => [
86+
'preference1' => 'newPreferenceValue1', 'preference2' => 'preferenceValue2'
87+
]
88+
]
89+
];
90+
}
91+
}

0 commit comments

Comments
 (0)