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