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