Skip to content

Commit 487edad

Browse files
Fix Static Tests build
1 parent 67b3f6e commit 487edad

File tree

2 files changed

+77
-39
lines changed

2 files changed

+77
-39
lines changed

lib/internal/Magento/Framework/ObjectManager/Factory/AbstractFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ protected function createObject($type, $args)
120120
try {
121121
return new $type(...array_values($args));
122122
} catch (\TypeError $exception) {
123-
/** @var LoggerInterface $logger */
123+
/**
124+
* @var LoggerInterface $logger
125+
*/
124126
$logger = ObjectManager::getInstance()->get(LoggerInterface::class);
125127
$logger->critical(
126128
sprintf('Type Error occurred when creating object: %s, %s', $type, $exception->getMessage())
@@ -249,7 +251,7 @@ protected function resolveArgumentsInRuntime($requestedType, array $parameters,
249251
}
250252

251253
if ($isVariadic && is_array($argument)) {
252-
$resolvedArguments = array_merge($resolvedArguments, $argument);
254+
$resolvedArguments += $argument;
253255
} else {
254256
$this->resolveArgument($argument, $paramType, $paramDefault, $paramName, $requestedType);
255257
$resolvedArguments[] = $argument;

lib/internal/Magento/Framework/ObjectManager/Test/Unit/Factory/FactoryTest.php

Lines changed: 73 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,34 @@ public function testCreateNoArgs()
5050
}
5151

5252
/**
53-
* @expectedException \UnexpectedValueException
53+
* @expectedException \UnexpectedValueException
5454
* @expectedExceptionMessage Invalid parameter configuration provided for $firstParam argument
5555
*/
5656
public function testResolveArgumentsException()
5757
{
5858
$configMock = $this->createMock(\Magento\Framework\ObjectManager\Config\Config::class);
59-
$configMock->expects($this->once())->method('getArguments')
60-
->will($this->returnValue([
61-
'firstParam' => 1,
62-
]));
59+
$configMock->expects($this->once())->method('getArguments')->will(
60+
$this->returnValue(
61+
[
62+
'firstParam' => 1,
63+
]
64+
)
65+
);
6366

6467
$definitionsMock = $this->createMock(\Magento\Framework\ObjectManager\DefinitionInterface::class);
65-
$definitionsMock->expects($this->once())->method('getParameters')
66-
->will($this->returnValue([[
67-
'firstParam', 'string', true, 'default_val', false
68-
]]));
68+
$definitionsMock->expects($this->once())->method('getParameters')->will(
69+
$this->returnValue(
70+
[
71+
[
72+
'firstParam',
73+
'string',
74+
true,
75+
'default_val',
76+
false
77+
]
78+
]
79+
)
80+
);
6981

7082
$this->factory = new Developer(
7183
$configMock,
@@ -80,9 +92,14 @@ public function testResolveArgumentsException()
8092
);
8193
}
8294

95+
/**
96+
* Test create with one arg
97+
*/
8398
public function testCreateOneArg()
8499
{
85-
/** @var \Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\OneScalar $result */
100+
/**
101+
* @var \Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\OneScalar $result
102+
*/
86103
$result = $this->factory->create(
87104
\Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\OneScalar::class,
88105
['foo' => 'bar']
@@ -91,6 +108,9 @@ public function testCreateOneArg()
91108
$this->assertEquals('bar', $result->getFoo());
92109
}
93110

111+
/**
112+
* Test create with injectable
113+
*/
94114
public function testCreateWithInjectable()
95115
{
96116
// let's imitate that One is injectable by providing DI configuration for it
@@ -101,7 +121,9 @@ public function testCreateWithInjectable()
101121
],
102122
]
103123
);
104-
/** @var \Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\Two $result */
124+
/**
125+
* @var \Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\Two $result
126+
*/
105127
$result = $this->factory->create(\Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\Two::class);
106128
$this->assertInstanceOf(\Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\Two::class, $result);
107129
$this->assertInstanceOf(
@@ -113,8 +135,8 @@ public function testCreateWithInjectable()
113135
}
114136

115137
/**
116-
* @param string $startingClass
117-
* @param string $terminationClass
138+
* @param string $startingClass
139+
* @param string $terminationClass
118140
* @dataProvider circularDataProvider
119141
*/
120142
public function testCircular($startingClass, $terminationClass)
@@ -139,23 +161,30 @@ public function circularDataProvider()
139161
];
140162
}
141163

164+
/**
165+
* Test create using reflection
166+
*/
142167
public function testCreateUsingReflection()
143168
{
144169
$type = \Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\Polymorphous::class;
145170
$definitions = $this->createMock(\Magento\Framework\ObjectManager\DefinitionInterface::class);
146171
// should be more than defined in "switch" of create() method
147-
$definitions->expects($this->once())->method('getParameters')->with($type)->will($this->returnValue([
148-
['one', null, false, null, false],
149-
['two', null, false, null, false],
150-
['three', null, false, null, false],
151-
['four', null, false, null, false],
152-
['five', null, false, null, false],
153-
['six', null, false, null, false],
154-
['seven', null, false, null, false],
155-
['eight', null, false, null, false],
156-
['nine', null, false, null, false],
157-
['ten', null, false, null, false],
158-
]));
172+
$definitions->expects($this->once())->method('getParameters')->with($type)->will(
173+
$this->returnValue(
174+
[
175+
['one', null, false, null, false],
176+
['two', null, false, null, false],
177+
['three', null, false, null, false],
178+
['four', null, false, null, false],
179+
['five', null, false, null, false],
180+
['six', null, false, null, false],
181+
['seven', null, false, null, false],
182+
['eight', null, false, null, false],
183+
['nine', null, false, null, false],
184+
['ten', null, false, null, false],
185+
]
186+
)
187+
);
159188
$factory = new Developer($this->config, null, $definitions);
160189
$result = $factory->create(
161190
$type,
@@ -178,9 +207,9 @@ public function testCreateUsingReflection()
178207
/**
179208
* Test create objects with variadic argument in constructor
180209
*
181-
* @param $createArgs
182-
* @param $expectedArg0
183-
* @param $expectedArg1
210+
* @param $createArgs
211+
* @param $expectedArg0
212+
* @param $expectedArg1
184213
* @dataProvider testCreateUsingVariadicDataProvider
185214
*/
186215
public function testCreateUsingVariadic(
@@ -191,20 +220,24 @@ public function testCreateUsingVariadic(
191220
$type = \Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\Variadic::class;
192221
$definitions = $this->createMock(\Magento\Framework\ObjectManager\DefinitionInterface::class);
193222

194-
$definitions->expects($this->once())->method('getParameters')->with($type)->will($this->returnValue([
195-
[
223+
$definitions->expects($this->once())->method('getParameters')->with($type)->will(
224+
$this->returnValue(
225+
[
226+
[
196227
'oneScalars',
197228
\Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\OneScalar::class,
198229
false,
199230
[],
200231
true
201-
],
202-
]));
232+
],
233+
]
234+
)
235+
);
203236
$factory = new Developer($this->config, null, $definitions);
204237

205-
206-
207-
/** @var \Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\Variadic $variadic */
238+
/**
239+
* @var \Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\Variadic $variadic
240+
*/
208241
$variadic = is_null($createArgs)
209242
? $factory->create($type)
210243
: $factory->create($type, $createArgs);
@@ -216,7 +249,8 @@ public function testCreateUsingVariadic(
216249
/**
217250
* @return array
218251
*/
219-
public function testCreateUsingVariadicDataProvider() {
252+
public function testCreateUsingVariadicDataProvider()
253+
{
220254
$oneScalar1 = $this->createMock(\Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\OneScalar::class);
221255
$oneScalar2 = $this->createMock(\Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\OneScalar::class);
222256

@@ -272,7 +306,9 @@ public function testCreateVariadicFromDiConfig()
272306
],
273307
]
274308
);
275-
/** @var \Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\Variadic $variadic */
309+
/**
310+
* @var \Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\Variadic $variadic
311+
*/
276312
$variadic = $this->factory->create(\Magento\Framework\ObjectManager\Test\Unit\Factory\Fixture\Variadic::class);
277313

278314
$this->assertSame($oneScalar1, $variadic->getOneScalarByKey(0));

0 commit comments

Comments
 (0)