public static function __called($class, $instance, $method, $args)
{
// Record the call as most recent first
array_unshift(self::$_call_list, array('class' => $class, 'instance' => $instance, 'method' => $method, 'args' => $args));
// Look up any stubbed responses
if (isset(self::$_responses[$instance][$method])) {
// Find the first one that matches the called-with arguments
foreach (self::$_responses[$instance][$method] as $i => &$matcher) {
if (self::_arguments_match($class, $method, $matcher['args'], $args)) {
// Consume the next response - except the last one, which repeats indefinitely
if (count($matcher['steps']) > 1) {
return array_shift($matcher['steps']);
} else {
return reset($matcher['steps']);
}
}
}
}
}