@@ -142,43 +142,32 @@ protected function stub(MethodInvocation $invocation, $params)
142
142
{
143
143
$ name = $ invocation ->getMethod ();
144
144
145
- return $ this ->stubIteratively ($ name , $ params , $ invocation );
145
+ $ replacedMethod = $ params [$ name ];
146
+
147
+ $ replacedMethod = $ this ->turnToClosure ($ replacedMethod );
148
+
149
+ if ($ invocation ->isStatic ()) {
150
+ $ replacedMethod = \Closure::bind ($ replacedMethod , null , $ invocation ->getThis ());
151
+ } else {
152
+ $ replacedMethod = $ replacedMethod ->bindTo ($ invocation ->getThis (), get_class ($ invocation ->getThis ()));
153
+ }
154
+ return call_user_func_array ($ replacedMethod , $ invocation ->getArguments ());
146
155
}
147
156
148
157
protected function stubMagicMethod (MethodInvocation $ invocation , $ params )
149
158
{
150
159
$ args = $ invocation ->getArguments ();
151
160
$ name = array_shift ($ args );
152
161
153
- return $ this ->stubIteratively ($ name , $ params , $ invocation );
154
- }
155
-
156
- protected function stubIteratively ($ name , $ params , MethodInvocation $ invocation )
157
- {
158
- $ replacedMethods = $ params [$ name ];
159
-
160
- if (!is_array ($ replacedMethods )) $ replacedMethods = [$ replacedMethods ];
161
-
162
- $ result = __AM_CONTINUE__ ;
163
-
164
- while ($ result === __AM_CONTINUE__ && count ($ replacedMethods ) > 0 ) {
165
- $ replacedMethod = array_pop ($ replacedMethods );
166
- $ result = $ this ->doStub ($ invocation , $ replacedMethod );
167
- }
168
-
169
- return $ result ;
170
- }
171
-
172
- protected function doStub (MethodInvocation $ invocation , $ replacedMethod )
173
- {
162
+ $ replacedMethod = $ params [$ name ];
174
163
$ replacedMethod = $ this ->turnToClosure ($ replacedMethod );
175
164
176
165
if ($ invocation ->isStatic ()) {
177
- $ replacedMethod = \Closure::bind ($ replacedMethod , null , $ invocation ->getThis ());
166
+ \Closure::bind ($ replacedMethod , null , $ invocation ->getThis ());
178
167
} else {
179
168
$ replacedMethod = $ replacedMethod ->bindTo ($ invocation ->getThis (), get_class ($ invocation ->getThis ()));
180
169
}
181
- return call_user_func_array ($ replacedMethod , $ invocation -> getArguments () );
170
+ return call_user_func_array ($ replacedMethod , $ args );
182
171
}
183
172
184
173
@@ -194,7 +183,7 @@ public function registerClass($class, $params = array())
194
183
{
195
184
$ class = ltrim ($ class ,'\\' );
196
185
if (isset ($ this ->classMap [$ class ])) {
197
- $ params = array_merge_recursive ($ this ->classMap [$ class ], $ params );
186
+ $ params = array_merge ($ this ->classMap [$ class ], $ params );
198
187
}
199
188
$ this ->methodMap = array_merge ($ this ->methodMap , array_keys ($ params ));
200
189
$ this ->classMap [$ class ] = $ params ;
@@ -204,7 +193,7 @@ public function registerObject($object, $params = array())
204
193
{
205
194
$ hash = spl_object_hash ($ object );
206
195
if (isset ($ this ->objectMap [$ hash ])) {
207
- $ params = array_merge_recursive ($ this ->objectMap [$ hash ], $ params );
196
+ $ params = array_merge ($ this ->objectMap [$ hash ], $ params );
208
197
}
209
198
$ this ->objectMap [$ hash ] = $ params ;
210
199
$ this ->methodMap = array_merge ($ this ->methodMap , array_keys ($ params ));
0 commit comments