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