public static function mock($function, $returnValue) { if (CIPHPUnitTestFunctionPatcher::isBlacklisted($function)) { throw new LogicException('Can\'t patch on ' . $function); } self::$mocks[$function] = $returnValue; }
public function leaveNode(PhpParser\Node $node) { if (!$node instanceof FuncCall) { return; } if (!$node->name instanceof Name) { return; } if ($node->name->isUnqualified() && !CIPHPUnitTestFunctionPatcher::isBlacklisted((string) $node->name)) { $replacement = new FullyQualified(array()); $replacement->set('CIPHPUnitTestFunctionPatcherProxy::' . (string) $node->name); $pos = $node->getAttribute('startTokenPos'); CIPHPUnitTestFunctionPatcher::$replacement[$pos] = '\\CIPHPUnitTestFunctionPatcherProxy::' . (string) $node->name; $node->name = $replacement; } }
public static function patch($source) { $patched = false; self::$replacement = []; $parser = new PhpParser\Parser(new PhpParser\Lexer(['usedAttributes' => ['startTokenPos', 'endTokenPos']])); $traverser = new PhpParser\NodeTraverser(); $traverser->addVisitor(new CIPHPUnitTestFunctionPatcherNodeVisitor()); $ast_orig = $parser->parse($source); $traverser->traverse($ast_orig); if (self::$replacement !== []) { $patched = true; $new_source = self::generateNewSource($source); } else { $new_source = $source; } return [$new_source, $patched]; }