PHP Class Qa\SoftMocks

ファイルを表示 Open project: badoo/soft-mocks Class Usage Examples

Public Properties

Property Type Description
$internal_functions

Public Methods

Method Description
call ( $callable, $args ) : mixed Generic method to call a callable, useful for proxying call_user_func* calls
callFunction ( $namespace, $func, $params )
callMethod ( $obj, $class, $method, $args, $check_mock = false )
callNew ( $class, $args )
callOriginal ( $callable, $args, $class = null )
callStaticMethod ( $class, $method, $args, $check_mock = false )
constDefined ( $const )
errorHandler ( $errno, $errstr, $errfile, $errline )
generateCode ( $args, ReflectionMethod | null $Rm ) : string Generate code that parses function parameters that are specified as string $args
getClassConst ( $class, $const )
getConst ( $namespace, $const )
getMockCode ( $self, $static, $method )
getMockForGenerator ( $class, $method )
ignoreClass ( string $class )
ignoreConstant ( string $constant )
ignoreFiles ( $files )
ignoreFunction ( string $function )
init ( )
isCallable ( $callable )
isGeneratorMocked ( $class, $method )
isMocked ( $self, $static, $method )
printBackTrace ( Exception $e = null )
redefineConstant ( $constantName, $value )
redefineFunction ( $func, $functionArgs, $fakeCode )
redefineGenerator ( $class, $method, Generator $replacement )
redefineMethod ( string $class, string $method, string $functionArgs, string $fakeCode, boolean $strict = true ) Redefine method $class::$method with args list specified by $functionArgs (args list must be compatible with original function, you can specify only variable names) by using code $fakeCode instead of original function code.
redefineNew ( $class, callable $constructorFunc )
removeConstant ( $constantName )
replaceFilename ( $file, $raw = false )
restoreAll ( )
restoreAllConstants ( )
restoreAllNew ( )
restoreConstant ( $constantName )
restoreFunction ( $func )
restoreGenerator ( $class, $method )
restoreMethod ( $class, $method )
restoreNew ( $class )
rewrite ( $file )
setLockFilePath ( $lock_file_path )
setMocksCachePath ( string $mocks_cache_path )
setPhpParserPath ( $php_parser_path )
setPhpunitPath ( string $phpunit_path )
setRewriteInternal ( boolean $rewrite_internal )

Protected Methods

Method Description
debug ( $message )

Private Methods

Method Description
createRewrittenFile ( $file, $target_file )
doRewrite ( $file )
getDeclaringTrait ( $class, $method )
getVersion ( )
injectIntoPhpunit ( )
recursiveGetTraits ( ReflectionClass $Rc ) : ReflectionClass[]
rewriteContents ( $orig_file, $target_file, $contents )
staticContextIsOk ( $self, $static, $method ) see \QA\SoftMocks\SoftMocksTest::testParentMismatch to see when getDeclaringClass check is needed

Method Details

call() public static method

Generic method to call a callable, useful for proxying call_user_func* calls
public static call ( $callable, $args ) : mixed
$callable
$args
return mixed

callFunction() public static method

public static callFunction ( $namespace, $func, $params )

callMethod() public static method

public static callMethod ( $obj, $class, $method, $args, $check_mock = false )

callNew() public static method

public static callNew ( $class, $args )

callOriginal() public static method

public static callOriginal ( $callable, $args, $class = null )

callStaticMethod() public static method

public static callStaticMethod ( $class, $method, $args, $check_mock = false )

constDefined() public static method

public static constDefined ( $const )

debug() protected static method

protected static debug ( $message )

errorHandler() public static method

public static errorHandler ( $errno, $errstr, $errfile, $errline )

generateCode() public static method

Generate code that parses function parameters that are specified as string $args
public static generateCode ( $args, ReflectionMethod | null $Rm ) : string
$args
$Rm ReflectionMethod | null
return string

getClassConst() public static method

public static getClassConst ( $class, $const )

getConst() public static method

public static getConst ( $namespace, $const )

getMockCode() public static method

public static getMockCode ( $self, $static, $method )

getMockForGenerator() public static method

public static getMockForGenerator ( $class, $method )

ignoreClass() public static method

public static ignoreClass ( string $class )
$class string - Do not allow to mock $class

ignoreConstant() public static method

public static ignoreConstant ( string $constant )
$constant string - Do not allow to mock $constant

ignoreFiles() public static method

public static ignoreFiles ( $files )

ignoreFunction() public static method

public static ignoreFunction ( string $function )
$function string - Do not allow to mock $function

init() public static method

public static init ( )

isCallable() public static method

public static isCallable ( $callable )

isGeneratorMocked() public static method

public static isGeneratorMocked ( $class, $method )

isMocked() public static method

public static isMocked ( $self, $static, $method )

printBackTrace() public static method

public static printBackTrace ( Exception $e = null )
$e Exception

redefineConstant() public static method

public static redefineConstant ( $constantName, $value )

redefineFunction() public static method

public static redefineFunction ( $func, $functionArgs, $fakeCode )

redefineGenerator() public static method

public static redefineGenerator ( $class, $method, Generator $replacement )
$replacement Generator

redefineMethod() public static method

There are two already defined variables that you can use in fake code: $mm_func_args = func_get_args(); $params is array of references to supplied arguments (func_get_args() does not contain refs in PHP5) You can use SoftMocks::callOriginal(...) for accessing original function/method as well Example: class A { public function b($c, &$d) { var_dump($c, $d); } } SoftMocks::redefineMethod(A::class, 'b', '$e, &$f', '$f = "hello";'); $a = 2; (new A())->b(1, $a); // nothing is printed here, so we intercepted the call var_dump($a); // string(5) "hello"
public static redefineMethod ( string $class, string $method, string $functionArgs, string $fakeCode, boolean $strict = true )
$class string
$method string Method of class to be intercepted
$functionArgs string List of argument names
$fakeCode string Code that will be eval'ed instead of function code
$strict boolean If strict=false then method of declaring class will also be mocked

redefineNew() public static method

public static redefineNew ( $class, callable $constructorFunc )
$constructorFunc callable

removeConstant() public static method

public static removeConstant ( $constantName )

replaceFilename() public static method

public static replaceFilename ( $file, $raw = false )

restoreAll() public static method

public static restoreAll ( )

restoreAllConstants() public static method

public static restoreAllConstants ( )

restoreAllNew() public static method

public static restoreAllNew ( )

restoreConstant() public static method

public static restoreConstant ( $constantName )

restoreFunction() public static method

public static restoreFunction ( $func )

restoreGenerator() public static method

public static restoreGenerator ( $class, $method )

restoreMethod() public static method

public static restoreMethod ( $class, $method )

restoreNew() public static method

public static restoreNew ( $class )

rewrite() public static method

public static rewrite ( $file )

setLockFilePath() public static method

public static setLockFilePath ( $lock_file_path )
$lock_file_path - Path to lock file that is used when file is rewritten

setMocksCachePath() public static method

public static setMocksCachePath ( string $mocks_cache_path )
$mocks_cache_path string - Path to cache of rewritten files

setPhpParserPath() public static method

public static setPhpParserPath ( $php_parser_path )
$php_parser_path - Part of path to PHP Parser so that it can be ignored when rewriting files

setPhpunitPath() public static method

public static setPhpunitPath ( string $phpunit_path )
$phpunit_path string - Part of path to phpunit so that it can be ignored when rewriting files

setRewriteInternal() public static method

public static setRewriteInternal ( boolean $rewrite_internal )
$rewrite_internal boolean

Property Details

$internal_functions public_oe static_oe property

public static $internal_functions