|
| 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' => [ |
| 66 | + 'preference1' => 'preferenceValue1', |
| 67 | + 'preference2' => 'preferenceValue2' |
| 68 | + ] |
| 69 | + ], |
| 70 | + 'configuration' => [ |
| 71 | + 'arguments' => [ |
| 72 | + 'type1' => serialize(['argument1_1' => 'newArgumentValue1_1']), |
| 73 | + 'type2' => serialize(['argument2_1' => 'newArgumentValue2_1']) |
| 74 | + ], |
| 75 | + 'instanceTypes' => [ |
| 76 | + 'instanceType2' => 'newInstanceTypeValue2', |
| 77 | + 'instanceType3' => 'newInstanceTypeValue3' |
| 78 | + ], |
| 79 | + 'preferences' => [ |
| 80 | + 'preference1' => 'newPreferenceValue1' |
| 81 | + ] |
| 82 | + ], |
| 83 | + 'expectedArguments' => [ |
| 84 | + 'type1' => ['argument1_1' => 'newArgumentValue1_1'], |
| 85 | + 'type2' => ['argument2_1' => 'newArgumentValue2_1'] |
| 86 | + ], |
| 87 | + 'expectedVirtualTypes' => [ |
| 88 | + 'instanceType1' => 'instanceTypeValue1', |
| 89 | + 'instanceType2' => 'newInstanceTypeValue2', |
| 90 | + 'instanceType3' => 'newInstanceTypeValue3' |
| 91 | + ], |
| 92 | + 'expectedPreferences' => [ |
| 93 | + 'preference1' => 'newPreferenceValue1', |
| 94 | + 'preference2' => 'preferenceValue2' |
| 95 | + ] |
| 96 | + ], |
| 97 | + |
| 98 | + [ |
| 99 | + 'initialData' => [ |
| 100 | + 'arguments' => null, |
| 101 | + 'instanceTypes' => null, |
| 102 | + 'preferences' => null |
| 103 | + ], |
| 104 | + 'configuration' => [ |
| 105 | + 'arguments' => [ |
| 106 | + 'type1' => serialize(['argument1_1' => 'newArgumentValue1_1']), |
| 107 | + 'type2' => serialize(['argument2_1' => 'newArgumentValue2_1']) |
| 108 | + ], |
| 109 | + 'instanceTypes' => [ |
| 110 | + 'instanceType2' => 'newInstanceTypeValue2', |
| 111 | + 'instanceType3' => 'newInstanceTypeValue3' |
| 112 | + ], |
| 113 | + 'preferences' => ['preference1' => 'newPreferenceValue1'] |
| 114 | + ], |
| 115 | + 'expectedArguments' => [ |
| 116 | + 'type1' => ['argument1_1' => 'newArgumentValue1_1'], |
| 117 | + 'type2' => ['argument2_1' => 'newArgumentValue2_1'] |
| 118 | + ], |
| 119 | + 'expectedVirtualTypes' => [ |
| 120 | + 'instanceType2' => 'newInstanceTypeValue2', |
| 121 | + 'instanceType3' => 'newInstanceTypeValue3' |
| 122 | + ], |
| 123 | + 'expectedPreferences' => [ |
| 124 | + 'preference1' => 'newPreferenceValue1' |
| 125 | + ] |
| 126 | + ] |
| 127 | + ]; |
| 128 | + } |
| 129 | +} |
0 commit comments