Skip to content

Commit d6fc508

Browse files
committed
Merge remote-tracking branch 'tsg/develop-pr6' into PRS
2 parents 22e1ecc + 88408b5 commit d6fc508

File tree

3 files changed

+129
-10
lines changed

3 files changed

+129
-10
lines changed

dev/tests/integration/testsuite/Magento/Framework/Search/Adapter/Mysql/AdapterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AdapterTest extends \PHPUnit_Framework_TestCase
2828
/**
2929
* @var \Magento\Framework\Search\Request\Builder
3030
*/
31-
private $requestBuilder;
31+
protected $requestBuilder;
3232

3333
/**
3434
* @var \Magento\Framework\ObjectManagerInterface
@@ -94,7 +94,7 @@ protected function createAdapter()
9494
/**
9595
* @return \Magento\Framework\Search\Response\QueryResponse
9696
*/
97-
private function executeQuery()
97+
protected function executeQuery()
9898
{
9999
/** @var \Magento\Framework\Search\RequestInterface $queryRequest */
100100
$queryRequest = $this->requestBuilder->create();

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ class Compiled implements ConfigInterface
3030
private $preferences;
3131

3232
/**
33-
* Constructor
34-
*
3533
* @param array $data
3634
*/
3735
public function __construct($data)
3836
{
39-
$this->arguments = $data['arguments'] ?: [];
40-
$this->virtualTypes = $data['instanceTypes'] ?: [];
41-
$this->preferences = $data['preferences'] ?: [];
37+
$this->arguments = isset($data['arguments']) && is_array($data['arguments'])
38+
? $data['arguments'] : [];
39+
$this->virtualTypes = isset($data['instanceTypes']) && is_array($data['instanceTypes'])
40+
? $data['instanceTypes'] : [];
41+
$this->preferences = isset($data['preferences']) && is_array($data['preferences'])
42+
? $data['preferences'] : [];
4243
}
4344

4445
/**
@@ -134,13 +135,13 @@ public function getPreference($type)
134135
*/
135136
public function extend(array $configuration)
136137
{
137-
$this->arguments = isset($configuration['arguments'])
138+
$this->arguments = isset($configuration['arguments']) && is_array($configuration['arguments'])
138139
? array_replace($this->arguments, $configuration['arguments'])
139140
: $this->arguments;
140-
$this->virtualTypes = isset($configuration['instanceTypes'])
141+
$this->virtualTypes = isset($configuration['instanceTypes']) && is_array($configuration['instanceTypes'])
141142
? array_replace($this->virtualTypes, $configuration['instanceTypes'])
142143
: $this->virtualTypes;
143-
$this->preferences = isset($configuration['preferences'])
144+
$this->preferences = isset($configuration['preferences']) && is_array($configuration['preferences'])
144145
? array_replace($this->preferences, $configuration['preferences'])
145146
: $this->preferences;
146147
}

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

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,122 @@ public function testGetArgumentsNotDefined()
165165
{
166166
$this->assertSame(null, $this->compiled->getArguments('class_not_stored_in_config'));
167167
}
168+
169+
/**
170+
* Test that $arguments, $virtualTypes and $preferences initializing in construct must be array.
171+
*
172+
* @param $data
173+
* @param array $expectedResult
174+
*
175+
* @dataProvider constructorFieldsValidation
176+
*/
177+
public function testConstructorFieldsValidation($data, $expectedResult)
178+
{
179+
/** @var Compiled $compiled */
180+
$compiled = $this->objectManager->getObject(
181+
Compiled::class,
182+
[
183+
'data' => $data,
184+
]
185+
);
186+
187+
$reflection = new \ReflectionClass(Compiled::class);
188+
$arguments = $reflection->getProperty('arguments');
189+
$arguments->setAccessible(true);
190+
191+
$this->assertEquals($expectedResult['arguments'], $arguments->getValue($compiled));
192+
$this->assertEquals($expectedResult['preferences'], $compiled->getPreferences());
193+
$this->assertEquals($expectedResult['instanceTypes'], $compiled->getVirtualTypes());
194+
}
195+
196+
/**
197+
* Data provider for testConstructorFieldsValidation.
198+
*
199+
* @return array
200+
*/
201+
public function constructorFieldsValidation()
202+
{
203+
return [
204+
[
205+
'no array',
206+
[
207+
'arguments' => [],
208+
'instanceTypes' => [],
209+
'preferences' => [],
210+
],
211+
],
212+
[
213+
[
214+
'arguments' => 1,
215+
'instanceTypes' => [1, 2, 3],
216+
'preferences' => 'test',
217+
],
218+
[
219+
'arguments' => [],
220+
'instanceTypes' => [1, 2, 3],
221+
'preferences' => [],
222+
],
223+
],
224+
];
225+
}
226+
227+
/**
228+
* Test that $arguments, $virtualTypes and $preferences initializing in extend must be array.
229+
*
230+
* @param $data
231+
* @param array $expectedResult
232+
*
233+
* @dataProvider extendFieldsValidation
234+
*/
235+
public function testExtendFieldsValidation($data, $expectedResult)
236+
{
237+
/** @var Compiled $compiled */
238+
$compiled = $this->objectManager->getObject(
239+
Compiled::class,
240+
[
241+
'data' => $data,
242+
]
243+
);
244+
245+
$compiled->extend($data);
246+
247+
$reflection = new \ReflectionClass(Compiled::class);
248+
$arguments = $reflection->getProperty('arguments');
249+
$arguments->setAccessible(true);
250+
251+
$this->assertEquals($expectedResult['arguments'], $arguments->getValue($compiled));
252+
$this->assertEquals($expectedResult['preferences'], $compiled->getPreferences());
253+
$this->assertEquals($expectedResult['instanceTypes'], $compiled->getVirtualTypes());
254+
}
255+
256+
/**
257+
* Data provider for testExtendFieldsValidation.
258+
*
259+
* @return array
260+
*/
261+
public function extendFieldsValidation()
262+
{
263+
return [
264+
[
265+
[],
266+
[
267+
'arguments' => [],
268+
'instanceTypes' => [],
269+
'preferences' => [],
270+
],
271+
],
272+
[
273+
[
274+
'arguments' => 1,
275+
'instanceTypes' => [1, 2, 3],
276+
'preferences' => 'test',
277+
],
278+
[
279+
'arguments' => [],
280+
'instanceTypes' => [1, 2, 3],
281+
'preferences' => [],
282+
],
283+
],
284+
];
285+
}
168286
}

0 commit comments

Comments
 (0)