PHP Class ShortifyPunit\ShortifyPunit

Inheritance: use trait ShortifyPunit\Matcher\ArgumentMatcher, use trait ShortifyPunit\Mock\MockTrait
Mostra file Open project: danrevah/shortifypunit Class Usage Examples

Public Methods

Method Description
__callStatic ( $name, $arguments ) : mixed Call static function is used to detect calls to protected & private methods
getReturnValues ( ) : array
mock ( $mockedClass ) : mixed Mocking interfaces & classes
partialMock ( $mockedClass ) : mixed Partial Mocking interfaces & classes
setReturnValues ( $returnValues )
spy ( $mockedClass )
verify ( $mock ) : ShortifyPunit\Verify\Verify Verifying method interactions
when ( ShortifyPunit\Mock\MockInterface $mock ) : ShortifyPunit\Stub\WhenChainCase Setting up a when case

Protected Methods

Method Description
_addChainedResponse ( $response ) Adding chained response to ReturnValues array
_createChainResponse ( $mockClassInstanceId, $mockClassType, $chainedMethodsBefore, $currentMethod, $args ) : null Setting up a chained mock response, function is called from mocked classes
_createResponse ( $className, $instanceId, $methodName, $arguments ) : Mixed | null Create response is a private method which is called from the Mocked classes returns a value which was set before in the When() function otherwise returning NULL
_generateInstanceId ( ) : integer Generating instance id, function is called from mocked classes
_isMethodStubbed ( $className, $instanceId, $methodName ) : boolean Checking if a method with specific arguments has been stubbed
_setWhenMockResponse ( $className, $instanceId, $methodName, $args, $action, $returns ) Setting up a mock response, function is called from mocked classes

Private Methods

Method Description
getMockHierarchyResponse ( $chainedMethodsBefore, $mockClassType, $mockClassInstanceId ) : mixed Returns the mock hierarchy response values
getMockReflection ( $mockedClass ) : ReflectionClass

Method Details

__callStatic() public static method

Call static function is used to detect calls to protected & private methods
public static __callStatic ( $name, $arguments ) : mixed
$name
$arguments
return mixed

_addChainedResponse() protected static method

Adding chained response to ReturnValues array
protected static _addChainedResponse ( $response )
$response

_createChainResponse() protected static method

Setting up a chained mock response, function is called from mocked classes
protected static _createChainResponse ( $mockClassInstanceId, $mockClassType, $chainedMethodsBefore, $currentMethod, $args ) : null
$mockClassInstanceId
$mockClassType
$chainedMethodsBefore
$currentMethod
$args
return null

_createResponse() protected static method

Create response is a private method which is called from the Mocked classes returns a value which was set before in the When() function otherwise returning NULL
protected static _createResponse ( $className, $instanceId, $methodName, $arguments ) : Mixed | null
$className
$instanceId
$methodName
$arguments
return Mixed | null | null

_generateInstanceId() protected static method

Generating instance id, function is called from mocked classes
protected static _generateInstanceId ( ) : integer
return integer

_isMethodStubbed() protected static method

Checking if a method with specific arguments has been stubbed
protected static _isMethodStubbed ( $className, $instanceId, $methodName ) : boolean
$className
$instanceId
$methodName
return boolean

_setWhenMockResponse() protected static method

Setting up a mock response, function is called from mocked classes
protected static _setWhenMockResponse ( $className, $instanceId, $methodName, $args, $action, $returns )
$className
$instanceId
$methodName
$args
$action
$returns

getReturnValues() public static method

public static getReturnValues ( ) : array
return array

mock() public static method

Mocking interfaces & classes
public static mock ( $mockedClass ) : mixed
$mockedClass
return mixed

partialMock() public static method

Partial Mocking interfaces & classes
public static partialMock ( $mockedClass ) : mixed
$mockedClass
return mixed

setReturnValues() public static method

public static setReturnValues ( $returnValues )
$returnValues

spy() public static method

Deprecation: use partialMock($mockedClass) instead
public static spy ( $mockedClass )

verify() public static method

Examples: ShortifyPunit::when($mock)->first_method()->returns(1); echo $mock->first_method(); // method called once ShortifyPunit::verify($mock)->first_method()->neverCalled(); // returns FALSE ShortifyPunit::verify($mock)->first_method()->atLeast(2); // returns FALSE ShortifyPunit::verify($mock)->first_method()->calledTimes(1); // returns TRUE echo $mock->first_method(); // method has been called twice ShortifyPunit::verify($mock)->first_method()->neverCalled(); // returns FALSE ShortifyPunit::verify($mock)->first_method()->atLeast(2); // returns TRUE ShortifyPunit::verify($mock)->first_method()->calledTimes(2); // returns TRUE
public static verify ( $mock ) : ShortifyPunit\Verify\Verify
$mock
return ShortifyPunit\Verify\Verify

when() public static method

Examples: Chain Stubbing ShortifyPunit::when($mock)->first_method()->second_method(1)->returns(1); ShortifyPunit::when($mock)->first_method()->second_method(2)->returns(2); ShortifyPunit::when($mock)->first_method(1)->second_method(1)->returns(3); ShortifyPunit::when($mock)->first_method(2)->second_method(2)->third_method()->returns(4); echo $mock->first_method()->second_method(1); // prints '1' echo $mock->first_method()->second_method(2); // prints '2' echo $mock->first_method(1)->second_method(1); // prints '3' echo $mock->first_method(2)->second_method(2)->third_method(); // prints '4'
public static when ( ShortifyPunit\Mock\MockInterface $mock ) : ShortifyPunit\Stub\WhenChainCase
$mock ShortifyPunit\Mock\MockInterface
return ShortifyPunit\Stub\WhenChainCase