PHP Class Qa\SoftMocks

Afficher le fichier Open project: badoo/soft-mocks Class Usage Examples

Méthodes publiques

Свойство Type Description
$internal_functions

Méthodes publiques

Méthode 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 )

Méthodes protégées

Méthode Description
debug ( $message )

Private Methods

Méthode 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 méthode

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

callFunction() public static méthode

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

callMethod() public static méthode

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

callNew() public static méthode

public static callNew ( $class, $args )

callOriginal() public static méthode

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

callStaticMethod() public static méthode

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

constDefined() public static méthode

public static constDefined ( $const )

debug() protected static méthode

protected static debug ( $message )

errorHandler() public static méthode

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

generateCode() public static méthode

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

getClassConst() public static méthode

public static getClassConst ( $class, $const )

getConst() public static méthode

public static getConst ( $namespace, $const )

getMockCode() public static méthode

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

getMockForGenerator() public static méthode

public static getMockForGenerator ( $class, $method )

ignoreClass() public static méthode

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

ignoreConstant() public static méthode

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

ignoreFiles() public static méthode

public static ignoreFiles ( $files )

ignoreFunction() public static méthode

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

init() public static méthode

public static init ( )

isCallable() public static méthode

public static isCallable ( $callable )

isGeneratorMocked() public static méthode

public static isGeneratorMocked ( $class, $method )

isMocked() public static méthode

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

printBackTrace() public static méthode

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

redefineConstant() public static méthode

public static redefineConstant ( $constantName, $value )

redefineFunction() public static méthode

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

redefineGenerator() public static méthode

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

redefineMethod() public static méthode

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 méthode

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

removeConstant() public static méthode

public static removeConstant ( $constantName )

replaceFilename() public static méthode

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

restoreAll() public static méthode

public static restoreAll ( )

restoreAllConstants() public static méthode

public static restoreAllConstants ( )

restoreAllNew() public static méthode

public static restoreAllNew ( )

restoreConstant() public static méthode

public static restoreConstant ( $constantName )

restoreFunction() public static méthode

public static restoreFunction ( $func )

restoreGenerator() public static méthode

public static restoreGenerator ( $class, $method )

restoreMethod() public static méthode

public static restoreMethod ( $class, $method )

restoreNew() public static méthode

public static restoreNew ( $class )

rewrite() public static méthode

public static rewrite ( $file )

setLockFilePath() public static méthode

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

setMocksCachePath() public static méthode

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

setPhpParserPath() public static méthode

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 méthode

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 méthode

public static setRewriteInternal ( boolean $rewrite_internal )
$rewrite_internal boolean

Property Details

$internal_functions public_oe static_oe property

public static $internal_functions