PHP Класс SimpleMock, simpletest

@package SimpleTest
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__construct ( ) Creates an empty action list and expectation list.
atTestEnd ( string $test_method, SimpleTestCase &$test ) Receives event from unit test that the current test method has finished.
disableExpectationNameChecks ( ) Disables a name check when setting expectations.
errorAt ( integer $timing, string $method, object $error = 'A mock error', array $args = false, integer $severity = E_USER_ERROR ) Sets up a trigger to throw an error upon a specific method call.
errorOn ( string $method, object $error = 'A mock error', array $args = false, integer $severity = E_USER_ERROR ) Sets up a trigger to throw an error upon the method call.
expect ( string $method, array $args, string $message = '%s' ) Sets up an expected call with a set of expected parameters in that call.
expectAt ( integer $timing, string $method, array $args, string $message = '%s' ) Sets up an expected call with a set of expected parameters in that call.
expectAtLeastOnce ( string $method, array $args = false, string $message = '%s' ) Convenience method for requiring a method call.
expectCallCount ( string $method, integer $count, string $message = '%s' ) Sets an expectation for the number of times a method will be called.
expectMaximumCallCount ( string $method, integer $count, string $message = '%s' ) Sets the number of times a method may be called before a test failure is triggered.
expectMinimumCallCount ( string $method, integer $count, string $message = '%s' ) Sets the number of times to call a method to prevent a failure on the tally.
expectNever ( string $method, string $message = '%s' ) Convenience method for barring a method call.
expectOnce ( string $method, array $args = false, string $message = '%s' ) Convenience method for a single method call.
getCallCount ( string $method ) : integer Fetches the call count of a method so far.
invoke ( string $method, array $args ) : mixed Returns the expected value for the method name and checks expectations.
replaceWildcards ( array $args ) : array Replaces wildcard matches with wildcard expectations in the argument list.
returns ( string $method, mixed $value, array $args = false ) Sets a return for a parameter list that will be passed on by all calls to this method that match.
returnsAt ( integer $timing, string $method, mixed $value, array $args = false ) Sets a return for a parameter list that will be passed only when the required call count is reached.
returnsByReference ( string $method, mixed &$reference, array $args = false ) Sets a return for a parameter list that will be passed by reference for all calls.
returnsByReferenceAt ( integer $timing, string $method, mixed &$reference, array $args = false ) Sets a return for a parameter list that will be passed by value only when the required call count is reached.
returnsByValue ( string $method, mixed $value, array $args = false ) Sets a return for a parameter list that will be passed by value for all calls to this method.
returnsByValueAt ( integer $timing, string $method, mixed $value, array $args = false ) Sets a return for a parameter list that will be passed by value only when the required call count is reached.
throwAt ( integer $timing, string $method, object $exception = false, array $args = false ) Sets up a trigger to throw an exception upon the method call.
throwOn ( string $method, object $exception = false, array $args = false ) Sets up a trigger to throw an exception upon the method call.

Защищенные методы

Метод Описание
addCall ( string $method, array $args ) Adds one to the call count of a method.
checkArgumentsIsArray ( mixed $args, string $task ) : boolean Die if bad arguments array is passed.
checkExpectations ( string $method, array $args, integer $timing ) Tests the arguments against expectations.
dieOnNoMethod ( string $method, string $task ) Triggers a PHP error if the method is not part of this object.
emulateCall ( string $method, array $args, integer $step ) : mixed Finds the return value matching the incoming arguments.
getCurrentTestCase ( ) : SimpeTestCase Finds currently running test.

Приватные методы

Метод Описание
disableEStrict ( ) Our mock has to be able to return anything, including variable references.
restoreEStrict ( integer $was ) Restores the E_STRICT level if it was previously set.

Описание методов

__construct() публичный Метод

All call counts are set to zero.
public __construct ( )

addCall() защищенный Метод

Adds one to the call count of a method.
protected addCall ( string $method, array $args )
$method string Method called.
$args array Arguments as an array.

atTestEnd() публичный Метод

Totals up the call counts and triggers a test assertion if a test is present for expected call counts.
public atTestEnd ( string $test_method, SimpleTestCase &$test )
$test_method string Current method name.
$test SimpleTestCase Test to send message to.

checkArgumentsIsArray() защищенный Метод

Die if bad arguments array is passed.
protected checkArgumentsIsArray ( mixed $args, string $task ) : boolean
$args mixed The arguments value to be checked.
$task string Description of task attempt.
Результат boolean Valid arguments

checkExpectations() защищенный Метод

Tests the arguments against expectations.
protected checkExpectations ( string $method, array $args, integer $timing )
$method string Method to check.
$args array Argument list to match.
$timing integer The position of this call in the call history.

dieOnNoMethod() защищенный Метод

Triggers a PHP error if the method is not part of this object.
protected dieOnNoMethod ( string $method, string $task )
$method string Name of method.
$task string Description of task attempt.

disableExpectationNameChecks() публичный Метод

This hack is needed for the partial mocks.

emulateCall() защищенный Метод

If there is no matching value found, then an error is triggered.
protected emulateCall ( string $method, array $args, integer $step ) : mixed
$method string Method name.
$args array Calling arguments.
$step integer Current position in the call history.
Результат mixed Stored return or other action.

errorAt() публичный Метод

Sets up a trigger to throw an error upon a specific method call.
public errorAt ( integer $timing, string $method, object $error = 'A mock error', array $args = false, integer $severity = E_USER_ERROR )
$timing integer When to throw the exception. A value of 0 throws immediately. A value of 1 actually allows one call to this method before throwing. 2 will allow two calls before throwing and so on.
$method string Method name to throw on.
$error object Error message to trigger.
$args array Optional argument list filter. If given then the exception will only be thrown if the method call matches the arguments.
$severity integer The PHP severity level. Defaults to E_USER_ERROR.

errorOn() публичный Метод

Sets up a trigger to throw an error upon the method call.
public errorOn ( string $method, object $error = 'A mock error', array $args = false, integer $severity = E_USER_ERROR )
$method string Method name to throw on.
$error object Error message to trigger.
$args array Optional argument list filter. If given then the exception will only be thrown if the method call matches the arguments.
$severity integer The PHP severity level. Defaults to E_USER_ERROR.

expect() публичный Метод

All calls will be compared to these expectations regardless of when the call is made.
public expect ( string $method, array $args, string $message = '%s' )
$method string Method call to test.
$args array Expected parameters for the call including wildcards.
$message string Overridden message.

expectAt() публичный Метод

The expected call count will be adjusted if it is set too low to reach this call.
public expectAt ( integer $timing, string $method, array $args, string $message = '%s' )
$timing integer Number of calls in the future at which to test. Next call is 0.
$method string Method call to test.
$args array Expected parameters for the call including wildcards.
$message string Overridden message.

expectAtLeastOnce() публичный Метод

Convenience method for requiring a method call.
public expectAtLeastOnce ( string $method, array $args = false, string $message = '%s' )
$method string Method call to track.
$args array Expected argument list or false for any arguments.
$message string Overridden message.

expectCallCount() публичный Метод

The tally method is used to check this.
public expectCallCount ( string $method, integer $count, string $message = '%s' )
$method string Method call to test.
$count integer Number of times it should have been called at tally.
$message string Overridden message.

expectMaximumCallCount() публичный Метод

Sets the number of times a method may be called before a test failure is triggered.
public expectMaximumCallCount ( string $method, integer $count, string $message = '%s' )
$method string Method call to test.
$count integer Most number of times it should have been called.
$message string Overridden message.

expectMinimumCallCount() публичный Метод

Sets the number of times to call a method to prevent a failure on the tally.
public expectMinimumCallCount ( string $method, integer $count, string $message = '%s' )
$method string Method call to test.
$count integer Least number of times it should have been called.
$message string Overridden message.

expectNever() публичный Метод

Convenience method for barring a method call.
public expectNever ( string $method, string $message = '%s' )
$method string Method call to ban.
$message string Overridden message.

expectOnce() публичный Метод

Convenience method for a single method call.
public expectOnce ( string $method, array $args = false, string $message = '%s' )
$method string Method call to track.
$args array Expected argument list or false for any arguments.
$message string Overridden message.

getCallCount() публичный Метод

Fetches the call count of a method so far.
public getCallCount ( string $method ) : integer
$method string Method name called.
Результат integer Number of calls so far.

getCurrentTestCase() защищенный Метод

Finds currently running test.
protected getCurrentTestCase ( ) : SimpeTestCase
Результат SimpeTestCase Current test case.

invoke() публичный Метод

Will generate anytest assertions as a result of expectations if there is a test present.
public invoke ( string $method, array $args ) : mixed
$method string Name of method to simulate.
$args array Arguments as an array.
Результат mixed Stored return.

replaceWildcards() публичный Метод

Replaces wildcard matches with wildcard expectations in the argument list.
public replaceWildcards ( array $args ) : array
$args array Raw argument list.
Результат array Argument list with expectations.

returns() публичный Метод

Sets a return for a parameter list that will be passed on by all calls to this method that match.
public returns ( string $method, mixed $value, array $args = false )
$method string Method name.
$value mixed Result of call by value/handle.
$args array List of parameters to match including wildcards.

returnsAt() публичный Метод

Sets a return for a parameter list that will be passed only when the required call count is reached.
public returnsAt ( integer $timing, string $method, mixed $value, array $args = false )
$timing integer Number of calls in the future to which the result applies. If not set then all calls will return the value.
$method string Method name.
$value mixed Result of call passed.
$args array List of parameters to match including wildcards.

returnsByReference() публичный Метод

Sets a return for a parameter list that will be passed by reference for all calls.
public returnsByReference ( string $method, mixed &$reference, array $args = false )
$method string Method name.
$reference mixed Result of the call will be this object.
$args array List of parameters to match including wildcards.

returnsByReferenceAt() публичный Метод

Sets a return for a parameter list that will be passed by value only when the required call count is reached.
public returnsByReferenceAt ( integer $timing, string $method, mixed &$reference, array $args = false )
$timing integer Number of calls in the future to which the result applies. If not set then all calls will return the value.
$method string Method name.
$reference mixed Result of the call will be this object.
$args array List of parameters to match including wildcards.

returnsByValue() публичный Метод

Sets a return for a parameter list that will be passed by value for all calls to this method.
public returnsByValue ( string $method, mixed $value, array $args = false )
$method string Method name.
$value mixed Result of call passed by value.
$args array List of parameters to match including wildcards.

returnsByValueAt() публичный Метод

Sets a return for a parameter list that will be passed by value only when the required call count is reached.
public returnsByValueAt ( integer $timing, string $method, mixed $value, array $args = false )
$timing integer Number of calls in the future to which the result applies. If not set then all calls will return the value.
$method string Method name.
$value mixed Result of call passed by value.
$args array List of parameters to match including wildcards.

throwAt() публичный Метод

Sets up a trigger to throw an exception upon the method call.
public throwAt ( integer $timing, string $method, object $exception = false, array $args = false )
$timing integer When to throw the exception. A value of 0 throws immediately. A value of 1 actually allows one call to this method before throwing. 2 will allow two calls before throwing and so on.
$method string Method name to throw on.
$exception object Exception object to throw. If not given then a simple Exception object is thrown.
$args array Optional argument list filter. If given then the exception will only be thrown if the method call matches the arguments.

throwOn() публичный Метод

Sets up a trigger to throw an exception upon the method call.
public throwOn ( string $method, object $exception = false, array $args = false )
$method string Method name to throw on.
$exception object Exception object to throw. If not given then a simple Exception object is thrown.
$args array Optional argument list filter. If given then the exception will only be thrown if the method call matches the arguments.