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