Skip to content

Commit

Permalink
Merge branch 'MAGETWO-59376' of https://github.com/magento-falcons/ma…
Browse files Browse the repository at this point in the history
…gento2ce into MAGETWO-59376
  • Loading branch information
shiftedreality committed Nov 2, 2016
2 parents a9e80c1 + 3d6bdee commit 0f97776
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,15 @@ public function getPreference($type)
*/
public function extend(array $configuration)
{
$this->arguments = $configuration['arguments'];
$this->virtualTypes = $configuration['instanceTypes'];
$this->preferences = $configuration['preferences'];
$this->arguments = isset($configuration['arguments'])
? array_replace($this->arguments, $configuration['arguments'])
: $this->arguments;
$this->virtualTypes = isset($configuration['instanceTypes'])
? array_replace($this->virtualTypes, $configuration['instanceTypes'])
: $this->virtualTypes;
$this->preferences = isset($configuration['preferences'])
? array_replace($this->preferences, $configuration['preferences'])
: $this->preferences;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\ObjectManager\Test\Unit\Config;

use Magento\Framework\ObjectManager\Config\Compiled as CompiledConfig;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;

class CompiledTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ObjectManagerHelper
*/
private $objectManagerHelper;

protected function setUp()
{
$this->objectManagerHelper = new ObjectManagerHelper($this);
}

/**
* @param array $initialData
* @param array $configuration
* @param array $expectedArguments
* @param array $expectedVirtualTypes
* @param array $expectedPreferences
*
* @dataProvider extendDataProvider
*/
public function testExtend(
array $initialData,
array $configuration,
array $expectedArguments,
array $expectedVirtualTypes,
array $expectedPreferences
) {
/** @var CompiledConfig $compiledConfig */
$compiledConfig = $this->objectManagerHelper->getObject(CompiledConfig::class, ['data' => $initialData]);
$compiledConfig->extend($configuration);

foreach ($expectedArguments as $type => $arguments) {
$this->assertEquals($arguments, $compiledConfig->getArguments($type));
}

$this->assertEquals($expectedVirtualTypes, $compiledConfig->getVirtualTypes());
$this->assertEquals($expectedPreferences, $compiledConfig->getPreferences());
}

/**
* @return array
*/
public function extendDataProvider()
{
return [
[
'initialData' => [
'arguments' => [
'type1' => serialize(['argument1_1' => 'argumentValue1_1', 'argument1_2' => 'argumentValue1_2'])
],
'instanceTypes' => [
'instanceType1' => 'instanceTypeValue1', 'instanceType2' => 'instanceTypeValue2'
],
'preferences' => ['preference1' => 'preferenceValue1', 'preference2' => 'preferenceValue2']
],
'configuration' => [
'arguments' => [
'type1' => serialize(['argument1_1' => 'newArgumentValue1_1']),
'type2' => serialize(['argument2_1' => 'newArgumentValue2_1'])
],
'instanceTypes' => [
'instanceType2' => 'newInstanceTypeValue2', 'instanceType3' => 'newInstanceTypeValue3'
],
'preferences' => ['preference1' => 'newPreferenceValue1']
],
'expectedArguments' => [
'type1' => ['argument1_1' => 'newArgumentValue1_1'],
'type2' => ['argument2_1' => 'newArgumentValue2_1']
],
'expectedVirtualTypes' => [
'instanceType1' => 'instanceTypeValue1', 'instanceType2' => 'newInstanceTypeValue2',
'instanceType3' => 'newInstanceTypeValue3'
],
'expectedPreferences' => [
'preference1' => 'newPreferenceValue1', 'preference2' => 'preferenceValue2'
]
]
];
}
}

0 comments on commit 0f97776

Please sign in to comment.