Class SimpleMock

Description

A base class or delegate that extends an

empty collection of methods that can have their return values set and expectations made of the calls upon them. The mock will assert the expectations against it's attached test case in addition to the server stub behaviour or returning preprogrammed responses.

Located in /mock_objects.php (line 639)


	
			
Method Summary
 SimpleMock SimpleMock ()
 void addCall (string $method, array $args)
 void atTestEnd (string $test_method,  &$test, SimpleTestCase $test)
 boolean checkArgumentsIsArray (mixed $args, string $task)
 void checkExpectations (string $method, array $args, integer $timing)
 void dieOnNoMethod (string $method, string $task)
 mixed &emulateCall (string $method, array $args, integer $step)
 void errorAt (integer $timing, string $method, [object $error = 'A mock error'], [array $args = false], [integer $severity = E_USER_ERROR])
 void errorOn (string $method, [object $error = 'A mock error'], [array $args = false], [integer $severity = E_USER_ERROR])
 void expect (string $method, array $args, [string $message = '%s'])
 void expectAt (integer $timing, string $method, array $args, [string $message = '%s'])
 void expectAtLeastOnce (string $method, [array $args = false], [string $message = '%s'])
 void expectCallCount (string $method, integer $count, [string $message = '%s'])
 void expectMaximumCallCount (string $method, integer $count, [string $message = '%s'])
 void expectMinimumCallCount (string $method, integer $count, [string $message = '%s'])
 void expectNever (string $method, [string $message = '%s'])
 void expectOnce (string $method, [array $args = false], [string $message = '%s'])
 integer getCallCount (string $method)
 SimpeTestCase getCurrentTestCase ()
 mixed &invoke (string $method, array $args)
 array replaceWildcards (array $args)
 void returns (string $method, mixed $value, [array $args = false])
 void returnsAt (integer $timing, string $method, mixed $value, [array $args = false])
 void returnsByReference (string $method,  &$reference, [array $args = false], mixed $reference)
 void returnsByReferenceAt (integer $timing, string $method,  &$reference, [array $args = false], mixed $reference)
 void returnsByValue (string $method, mixed $value, [array $args = false])
 void returnsByValueAt (integer $timing, string $method, mixed $value, [array $args = false])
 void setReturnReference ( $method,  &$reference, [ $args = false])
 void setReturnReferenceAt ( $timing,  $method,  &$reference, [ $args = false])
 void setReturnValue ( $method,  $value, [ $args = false])
 void setReturnValueAt ( $timing,  $method,  $value, [ $args = false])
 void throwAt (integer $timing, string $method, [object $exception = false], [array $args = false])
 void throwOn (string $method, [object $exception = false], [array $args = false])
Methods
Constructor SimpleMock (line 654)

Creates an empty action list and expectation list.

All call counts are set to zero.

SimpleMock SimpleMock ()
addCall (line 733)

Adds one to the call count of a method.

  • access: protected
void addCall (string $method, array $args)
  • string $method: Method called.
  • array $args: Arguments as an array.
atTestEnd (line 1088)

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.

void atTestEnd (string $test_method,  &$test, SimpleTestCase $test)
  • string $test_method: Current method name.
  • SimpleTestCase $test: Test to send message to.
  • &$test
checkArgumentsIsArray (line 687)

Die if bad arguments array is passed.

  • return: Valid arguments
  • access: protected
boolean checkArgumentsIsArray (mixed $args, string $task)
  • mixed $args: The arguments value to be checked.
  • string $task: Description of task attempt.
checkExpectations (line 1145)

Tests the arguments against expectations.

  • access: protected
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.
dieOnNoMethod (line 701)

Triggers a PHP error if the method is not part of this object.

  • access: protected
void dieOnNoMethod (string $method, string $task)
  • string $method: Name of method.
  • string $task: Description of task attempt.
disableExpectationNameChecks (line 669)

Disables a name check when setting expectations.

This hack is needed for the partial mocks.

void disableExpectationNameChecks ()
emulateCall (line 1134)

Finds the return value matching the incoming arguments. If there is no matching value found then an error is triggered.

  • return: Stored return or other action.
  • access: protected
mixed &emulateCall (string $method, array $args, integer $step)
  • string $method: Method name.
  • array $args: Calling arguments.
  • integer $step: Current position in the call history.
errorAt (line 1075)

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.
errorOn (line 1052)

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.
expect (line 877)

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.
expectAt (line 899)

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.
expectAtLeastOnce (line 991)

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.
expectCallCount (line 921)

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.
expectMaximumCallCount (line 936)

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.
expectMinimumCallCount (line 951)

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.
expectNever (line 964)

Convenience method for barring a method call.

void expectNever (string $method, [string $message = '%s'])
  • string $method: Method call to ban.
  • string $message: Overridden message.
expectOnce (line 976)

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.
getCallCount (line 745)

Fetches the call count of a method so far.

  • return: Number of calls so far.
integer getCallCount (string $method)
  • string $method: Method name called.
getCurrentTestCase (line 677)

Finds currently running test.

  • return: Current test case.
  • access: protected
SimpeTestCase getCurrentTestCase ()
invoke (line 1108)

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.

  • return: Stored return.
mixed &invoke (string $method, array $args)
  • string $method: Name of method to simulate.
  • array $args: Arguments as an array.
replaceWildcards (line 716)

Replaces wildcard matches with wildcard expectations in the argument list.

  • return: Argument list with expectations.
array replaceWildcards (array $args)
  • array $args: Raw argument list.
returns (line 762)

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.
returnsAt (line 780)

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.
returnsByReference (line 834)

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
returnsByReferenceAt (line 857)

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
returnsByValue (line 793)

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.
returnsByValueAt (line 816)

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.
setReturnReference (line 840)
  • deprecated:
void setReturnReference ( $method,  &$reference, [ $args = false])
  • $method
  • &$reference
  • $args
setReturnReferenceAt (line 863)
  • deprecated:
void setReturnReferenceAt ( $timing,  $method,  &$reference, [ $args = false])
  • $timing
  • $method
  • &$reference
  • $args
setReturnValue (line 799)
  • deprecated:
void setReturnValue ( $method,  $value, [ $args = false])
  • $method
  • $value
  • $args
setReturnValueAt (line 822)
  • deprecated:
void setReturnValueAt ( $timing,  $method,  $value, [ $args = false])
  • $timing
  • $method
  • $value
  • $args
throwAt (line 1034)

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.
throwOn (line 1010)

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.

Documentation generated on Sun, 31 Oct 2010 16:31:49 -0500 by phpDocumentor 1.4.3