/** * Set a function patch * * This method has '__' suffix, because if it matches real function name, * '__callStatic()' catch it. * * @param string $function function name * @param mixed $return_value return value or callable * @param string $class_name class::method to apply this patch * * @throws LogicException */ public static function patch__($function, $return_value, $class_method = null) { $function = strtolower($function); if (FunctionPatcher::isBlacklisted($function)) { $msg = "<red>Can't patch on '{$function}'. It is in blacklist.</red>"; self::outputMessage($msg); throw new LogicException($msg); } if (!FunctionPatcher::isWhitelisted($function)) { $msg = "<red>Can't patch on '{$function}'. It is not in whitelist. If you want to patch it, please add it to 'functions_to_patch' in 'tests/Bootstrap.php'. But note that there are some limitations. See <https://github.com/kenjis/ci-phpunit-test/blob/master/docs/HowToWriteTests.md#patching-functions> for details.</red>"; self::outputMessage($msg); throw new LogicException($msg); } self::$patches[$function] = $return_value; self::$patches_to_apply[$function] = strtolower($class_method); }
public function leaveNode(Node $node) { if (!$node instanceof FuncCall) { return; } if (!$node->name instanceof Name) { return; } if (!$node->name->isUnqualified()) { return; } if (FunctionPatcher::isWhitelisted((string) $node->name) && !FunctionPatcher::isBlacklisted((string) $node->name)) { $replacement = new FullyQualified(array()); $replacement->set('\\__FuncProxy__::' . (string) $node->name); $pos = $node->getAttribute('startTokenPos'); FunctionPatcher::$replacement[$pos] = '\\__FuncProxy__::' . (string) $node->name; $node->name = $replacement; } }