Creates an empty action list and expectation list.
All call counts are set to zero.
SimpleMock
SimpleMock
()
Adds one to the call count of a method.
void
addCall
(string $method, array $args)
-
string
$method: Method called.
-
array
$args: Arguments as an array.
Receives event from unit test that the current test method has finished. Totals up the call counts and triggers a test assertion if a test is present for expected call counts.
-
string
$test_method: Current method name.
-
SimpleTestCase
$test: Test to send message to.
-
&$test
Die if bad arguments array is passed.
boolean
checkArgumentsIsArray
(mixed $args, string $task)
-
mixed
$args: The arguments value to be checked.
-
string
$task: Description of task attempt.
Tests the arguments against expectations.
void
checkExpectations
(string $method, array $args, integer $timing)
-
string
$method: Method to check.
-
array
$args: Argument list to match.
-
integer
$timing: The position of this call in the call history.
Triggers a PHP error if the method is not part of this object.
void
dieOnNoMethod
(string $method, string $task)
-
string
$method: Name of method.
-
string
$task: Description of task attempt.
Disables a name check when setting expectations.
This hack is needed for the partial mocks.
void
disableExpectationNameChecks
()
Finds the return value matching the incoming arguments. If there is no matching value found then an error is triggered.
mixed
&emulateCall
(string $method, array $args, integer $step)
-
string
$method: Method name.
-
array
$args: Calling arguments.
-
integer
$step: Current position in the call history.
Sets up a trigger to throw an error upon a specific method call.
void
errorAt
(integer $timing, string $method, [object $error = 'A mock error'], [array $args = false], [integer $severity = E_USER_ERROR])
-
integer
$timing: 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.
-
string
$method: Method name to throw on.
-
object
$error: Error message to trigger.
-
array
$args: Optional argument list filter. If given then the exception will only be thrown if the method call matches the arguments.
-
integer
$severity: The PHP severity level. Defaults to E_USER_ERROR.
Sets up a trigger to throw an error upon the method call.
void
errorOn
(string $method, [object $error = 'A mock error'], [array $args = false], [integer $severity = E_USER_ERROR])
-
string
$method: Method name to throw on.
-
object
$error: Error message to trigger.
-
array
$args: Optional argument list filter. If given then the exception will only be thrown if the method call matches the arguments.
-
integer
$severity: The PHP severity level. Defaults to E_USER_ERROR.
Sets up an expected call with a set of expected parameters in that call. All calls will be compared to these expectations regardless of when the call is made.
void
expect
(string $method, array $args, [string $message = '%s'])
-
string
$method: Method call to test.
-
array
$args: Expected parameters for the call including wildcards.
-
string
$message: Overridden message.
Sets up an expected call with a set of expected parameters in that call. The expected call count will be adjusted if it is set too low to reach this call.
void
expectAt
(integer $timing, string $method, array $args, [string $message = '%s'])
-
integer
$timing: Number of calls in the future at which to test. Next call is 0.
-
string
$method: Method call to test.
-
array
$args: Expected parameters for the call including wildcards.
-
string
$message: Overridden message.
Convenience method for requiring a method call.
void
expectAtLeastOnce
(string $method, [array $args = false], [string $message = '%s'])
-
string
$method: Method call to track.
-
array
$args: Expected argument list or false for any arguments.
-
string
$message: Overridden message.
Sets an expectation for the number of times a method will be called. The tally method is used to check this.
void
expectCallCount
(string $method, integer $count, [string $message = '%s'])
-
string
$method: Method call to test.
-
integer
$count: Number of times it should have been called at tally.
-
string
$message: Overridden message.
Sets the number of times a method may be called before a test failure is triggered.
void
expectMaximumCallCount
(string $method, integer $count, [string $message = '%s'])
-
string
$method: Method call to test.
-
integer
$count: Most number of times it should have been called.
-
string
$message: Overridden message.
Sets the number of times to call a method to prevent a failure on the tally.
void
expectMinimumCallCount
(string $method, integer $count, [string $message = '%s'])
-
string
$method: Method call to test.
-
integer
$count: Least number of times it should have been called.
-
string
$message: Overridden message.
Convenience method for barring a method call.
void
expectNever
(string $method, [string $message = '%s'])
-
string
$method: Method call to ban.
-
string
$message: Overridden message.
Convenience method for a single method call.
void
expectOnce
(string $method, [array $args = false], [string $message = '%s'])
-
string
$method: Method call to track.
-
array
$args: Expected argument list or false for any arguments.
-
string
$message: Overridden message.
Fetches the call count of a method so far.
integer
getCallCount
(string $method)
-
string
$method: Method name called.
Finds currently running test.
SimpeTestCase
getCurrentTestCase
()
Returns the expected value for the method name and checks expectations. Will generate any test assertions as a result of expectations if there is a test present.
mixed
&invoke
(string $method, array $args)
-
string
$method: Name of method to simulate.
-
array
$args: Arguments as an array.
Replaces wildcard matches with wildcard expectations in the argument list.
array
replaceWildcards
(array $args)
-
array
$args: Raw argument list.
Sets a return for a parameter list that will be passed on by all calls to this method that match.
void
returns
(string $method, mixed $value, [array $args = false])
-
string
$method: Method name.
-
mixed
$value: Result of call by value/handle.
-
array
$args: List of parameters to match including wildcards.
Sets a return for a parameter list that will be passed only when the required call count is reached.
void
returnsAt
(integer $timing, string $method, mixed $value, [array $args = false])
-
integer
$timing: Number of calls in the future to which the result applies. If not set then all calls will return the value.
-
string
$method: Method name.
-
mixed
$value: Result of call passed.
-
array
$args: List of parameters to match including wildcards.
Sets a return for a parameter list that will be passed by reference for all calls.
void
returnsByReference
(string $method, &$reference, [array $args = false], mixed $reference)
-
string
$method: Method name.
-
mixed
$reference: Result of the call will be this object.
-
array
$args: List of parameters to match including wildcards.
-
&$reference
Sets a return for a parameter list that will be passed by value only when the required call count is reached.
void
returnsByReferenceAt
(integer $timing, string $method, &$reference, [array $args = false], mixed $reference)
-
integer
$timing: Number of calls in the future to which the result applies. If not set then all calls will return the value.
-
string
$method: Method name.
-
mixed
$reference: Result of the call will be this object.
-
array
$args: List of parameters to match including wildcards.
-
&$reference
Sets a return for a parameter list that will be passed by value for all calls to this method.
void
returnsByValue
(string $method, mixed $value, [array $args = false])
-
string
$method: Method name.
-
mixed
$value: Result of call passed by value.
-
array
$args: List of parameters to match including wildcards.
Sets a return for a parameter list that will be passed by value only when the required call count is reached.
void
returnsByValueAt
(integer $timing, string $method, mixed $value, [array $args = false])
-
integer
$timing: Number of calls in the future to which the result applies. If not set then all calls will return the value.
-
string
$method: Method name.
-
mixed
$value: Result of call passed by value.
-
array
$args: List of parameters to match including wildcards.
void
setReturnReference
( $method, &$reference, [ $args = false])
-
$method
-
&$reference
-
$args
void
setReturnReferenceAt
( $timing, $method, &$reference, [ $args = false])
-
$timing
-
$method
-
&$reference
-
$args
void
setReturnValue
( $method, $value, [ $args = false])
void
setReturnValueAt
( $timing, $method, $value, [ $args = false])
-
$timing
-
$method
-
$value
-
$args
Sets up a trigger to throw an exception upon the method call.
void
throwAt
(integer $timing, string $method, [object $exception = false], [array $args = false])
-
integer
$timing: 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.
-
string
$method: Method name to throw on.
-
object
$exception: Exception object to throw. If not given then a simple Exception object is thrown.
-
array
$args: Optional argument list filter. If given then the exception will only be thrown if the method call matches the arguments.
Sets up a trigger to throw an exception upon the method call.
void
throwOn
(string $method, [object $exception = false], [array $args = false])
-
string
$method: Method name to throw on.
-
object
$exception: Exception object to throw. If not given then a simple Exception object is thrown.
-
array
$args: Optional argument list filter. If given then the exception will only be thrown if the method call matches the arguments.