@@ -185,55 +185,50 @@ public function getObject($className, array $arguments = [])
185
185
*/
186
186
protected function getBuilder ($ className , array $ arguments )
187
187
{
188
- $ objectFactory = $ this ->_testObject ->getMock ('Magento\Framework\Api\ObjectFactory ' , [], [], '' , false );
189
-
190
188
if (!isset ($ arguments ['objectFactory ' ])) {
191
- $ arguments ['objectFactory ' ] = $ objectFactory ;
192
- }
189
+ $ objectFactory = $ this ->_testObject ->getMock ('Magento\Framework\Api\ObjectFactory ' , [], [], '' , false );
193
190
194
- $ constructArguments = $ this ->getConstructArguments ($ className , $ arguments );
195
- $ reflectionClass = new \ReflectionClass ($ className );
196
- $ builderObject = $ reflectionClass ->newInstanceArgs ($ constructArguments );
197
-
198
- $ objectFactory ->expects ($ this ->_testObject ->any ())
199
- ->method ('populateWithArray ' )
200
- ->will ($ this ->_testObject ->returnSelf ());
201
- $ objectFactory ->expects ($ this ->_testObject ->any ())
202
- ->method ('populate ' )
203
- ->will ($ this ->_testObject ->returnSelf ());
204
- $ objectFactory ->expects ($ this ->_testObject ->any ())
205
- ->method ('create ' )
206
- ->will ($ this ->_testObject ->returnCallback (
207
- function ($ className , $ arguments ) {
208
- $ reflectionClass = new \ReflectionClass ($ className );
209
- $ constructorMethod = $ reflectionClass ->getConstructor ();
210
- $ parameters = $ constructorMethod ->getParameters ();
211
- $ args = [];
212
- foreach ($ parameters as $ parameter ) {
213
- $ parameterName = $ parameter ->getName ();
214
- if (isset ($ arguments [$ parameterName ])) {
215
- $ args [] = $ arguments [$ parameterName ];
216
- } else {
217
- if ($ parameter ->isArray ()) {
218
- $ args [] = [];
219
- } elseif ($ parameter ->allowsNull ()) {
220
- $ args [] = null ;
191
+ $ objectFactory ->expects ($ this ->_testObject ->any ())
192
+ ->method ('populateWithArray ' )
193
+ ->will ($ this ->_testObject ->returnSelf ());
194
+ $ objectFactory ->expects ($ this ->_testObject ->any ())
195
+ ->method ('populate ' )
196
+ ->will ($ this ->_testObject ->returnSelf ());
197
+ $ objectFactory ->expects ($ this ->_testObject ->any ())
198
+ ->method ('create ' )
199
+ ->will ($ this ->_testObject ->returnCallback (
200
+ function ($ className , $ arguments ) {
201
+ $ reflectionClass = new \ReflectionClass ($ className );
202
+ $ constructorMethod = $ reflectionClass ->getConstructor ();
203
+ $ parameters = $ constructorMethod ->getParameters ();
204
+ $ args = [];
205
+ foreach ($ parameters as $ parameter ) {
206
+ $ parameterName = $ parameter ->getName ();
207
+ if (isset ($ arguments [$ parameterName ])) {
208
+ $ args [] = $ arguments [$ parameterName ];
221
209
} else {
222
- $ mock = $ this ->_getMockWithoutConstructorCall ($ parameter ->getClass ()->getName ());
223
- $ args [] = $ mock ;
210
+ if ($ parameter ->isArray ()) {
211
+ $ args [] = [];
212
+ } elseif ($ parameter ->allowsNull ()) {
213
+ $ args [] = null ;
214
+ } else {
215
+ $ mock = $ this ->_getMockWithoutConstructorCall ($ parameter ->getClass ()->getName ());
216
+ $ args [] = $ mock ;
217
+ }
224
218
}
225
219
}
220
+ return new $ className (...$ args );
226
221
}
222
+ ));
227
223
228
- return $ reflectionClass ->newInstanceArgs ($ args );
229
- }
230
- ));
224
+ $ arguments ['objectFactory ' ] = $ objectFactory ;
225
+ }
231
226
232
- return $ builderObject ;
227
+ return new $ className (... array_values ( $ this -> getConstructArguments ( $ className , $ arguments ))) ;
233
228
}
234
229
235
230
/**
236
- * Retrieve list of arguments that used for new object instance creation
231
+ * Retrieve associative array of arguments that used for new object instance creation
237
232
*
238
233
* @param string $className
239
234
* @param array $arguments
0 commit comments