Qa\SoftMocks::redefineFunction PHP Method

redefineFunction() public static method

public static redefineFunction ( $func, $functionArgs, $fakeCode )
    public static function redefineFunction($func, $functionArgs, $fakeCode)
    {
        if (self::$debug) {
            self::debug("Asked to redefine {$func}({$functionArgs})");
        }
        if (!self::$rewrite_internal && isset(self::$internal_func_mocks[$func])) {
            throw new \RuntimeException("Function {$func} is mocked internally, cannot mock");
        }
        if (SoftMocksTraverser::isFunctionIgnored($func)) {
            throw new \RuntimeException("Function {$func} cannot be mocked using Soft Mocks");
        }
        self::$func_mocks[$func] = ['args' => $functionArgs, 'code' => $fakeCode];
    }

Usage Example

Esempio n. 1
0
 public static function applyMocks()
 {
     \QA\SoftMocks::redefineConstant('TEST_CONSTANT_WITH_VALUE_42', 43);
     \QA\SoftMocks::redefineConstant('\\Example::STATIC_DO_SMTH_RESULT', 'Example::STATIC_DO_SMTH_RESULT value changed');
     \QA\SoftMocks::redefineFunction('someFunc', '$a', 'return 55 + $a;');
     \QA\SoftMocks::redefineMethod(Example::class, 'doSmthStatic', '', 'return "Example::doSmthStatic() redefined";');
     \QA\SoftMocks::redefineMethod(Example::class, 'doSmthDynamic', '', 'return "Example->doSmthDynamic() redefined";');
 }
All Usage Examples Of Qa\SoftMocks::redefineFunction