Skip to content

Commit f39dab0

Browse files
author
Igor Melnikov
committed
MAGETWO-60442: Add optional SerializerInterface dependency to child classes of \Magento\Framework\Config\Data
Fixing tests
1 parent 436fdb9 commit f39dab0

File tree

2 files changed

+74
-69
lines changed

2 files changed

+74
-69
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
*
43
* Copyright © 2016 Magento. All rights reserved.
54
* See COPYING.txt for license details.
65
*/

lib/internal/Magento/Framework/Test/Unit/ObjectManager/Config/CompiledTest.php

Lines changed: 74 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,87 +5,93 @@
55
*/
66
namespace Magento\Framework\Test\Unit\ObjectManager\Config;
77

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;
1011

1112
class CompiledTest extends \PHPUnit_Framework_TestCase
1213
{
1314
/**
14-
* @var ObjectManagerHelper
15+
* @var ObjectManager
1516
*/
16-
private $objectManagerHelper;
17-
18-
protected function setUp()
19-
{
20-
$this->objectManagerHelper = new ObjectManagerHelper($this);
21-
}
17+
private $objectManager;
2218

2319
/**
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
3121
*/
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;
4223

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);
4928
}
5029

51-
/**
52-
* @return array
53-
*/
54-
public function extendDataProvider()
30+
public function testExtend()
5531
{
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'
8856
]
8957
];
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());
9096
}
9197
}

0 commit comments

Comments
 (0)