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)


	
			
Variable Summary
Method Summary
 SimpleMock SimpleMock ()
 void atTestEnd (string $test_method,  &$test, SimpleTestCase $test)
 void errorAt ( $timing,  $method, [ $error = 'A mock error'], [ $args = false], [ $severity = E_USER_ERROR])
 void errorOn ( $method, [ $error = 'A mock error'], [ $args = false], [ $severity = E_USER_ERROR])
 void expect (string $method, array $args, [string $message = '%s'])
 void expectArguments ( $method,  $args, [ $message = '%s'])
 void expectArgumentsAt ( $timing,  $method,  $args, [ $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)
 void setReturnReference (string $method,  &$reference, [array $args = false], mixed $reference)
 void setReturnReferenceAt (integer $timing, string $method,  &$reference, [array $args = false], mixed $reference)
 void setReturnValue (string $method, mixed $value, [array $args = false])
 void setReturnValueAt (integer $timing, string $method, mixed $value, [array $args = false])
 void tally ()
 void throwAt ( $timing,  $method, [ $exception = false], [ $args = false])
 void throwOn (string $method, [ $exception = false], [ $args = false])
 void _addCall (string $method, array $args)
 void _dieOnNoMethod (string $method, string $task)
 mixed &_emulateCall (string $method, array $args, integer $step)
 SimpeTestCase &_getCurrentTestCase ()
Variables
mixed $_actions (line 640)
mixed $_call_counts (line 643)
mixed $_expected_args (line 646)
mixed $_expected_args_at (line 647)
mixed $_expected_counts (line 644)
mixed $_is_strict = true (line 642)
mixed $_max_counts (line 645)
mixed $_wildcard = MOCK_ANYTHING (line 641)
Methods
Constructor SimpleMock (line 654)

Creates an empty action list and expectation list.

All call counts are set to zero.

  • access: public
SimpleMock SimpleMock ()
atTestEnd (line 1036)

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.

  • access: public
void atTestEnd (string $test_method,  &$test, SimpleTestCase $test)
  • string $test_method: Current method name.
  • SimpleTestCase $test: Test to send message to.
  • &$test
disableExpectationNameChecks (line 671)

Disables a name check when setting expectations.

This hack is needed for the partial mocks.

  • access: public
void disableExpectationNameChecks ()
errorAt (line 1016)

Sets up a trigger to throw an error upon the method call.

void errorAt ( $timing,  $method, [ $error = 'A mock error'], [ $args = false], [ $severity = E_USER_ERROR])
  • $timing
  • $method
  • $error
  • $args
  • $severity
errorOn (line 1007)

Sets up a trigger to throw an error upon the method call.

void errorOn ( $method, [ $error = 'A mock error'], [ $args = false], [ $severity = E_USER_ERROR])
  • $method
  • $error
  • $args
  • $severity
expect (line 840)

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.

  • access: public
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.
expectArguments (line 853)
  • deprecated:
void expectArguments ( $method,  $args, [ $message = '%s'])
  • $method
  • $args
  • $message
expectArgumentsAt (line 886)
  • deprecated:
void expectArgumentsAt ( $timing,  $method,  $args, [ $message = '%s'])
  • $timing
  • $method
  • $args
  • $message
expectAt (line 870)

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.

  • access: public
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 975)

Convenience method for requiring a method call.

  • access: public
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 900)

Sets an expectation for the number of times a method will be called. The tally method is used to check this.

  • access: public
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 916)

Sets the number of times a method may be called before a test failure is triggered.

  • access: public
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 932)

Sets the number of times to call a method to prevent a failure on the tally.

  • access: public
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 946)

Convenience method for barring a method call.

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

Convenience method for a single method call.

  • access: public
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 754)

Fetches the call count of a method so far.

  • return: Number of calls so far.
  • access: public
integer getCallCount (string $method)
  • string $method: Method name called.
setReturnReference (line 805)

Sets a return for a parameter list that will be passed by reference for all calls.

  • access: public
void setReturnReference (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
setReturnReferenceAt (line 824)

Sets a return for a parameter list that will be passed by value only when the required call count is reached.

  • access: public
void setReturnReferenceAt (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
setReturnValue (line 772)

Sets a return for a parameter list that will be passed by value for all calls to this method.

  • access: public
void setReturnValue (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.
setReturnValueAt (line 791)

Sets a return for a parameter list that will be passed by value only when the required call count is reached.

  • access: public
void setReturnValueAt (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.
tally (line 1024)
  • deprecated:
void tally ()
throwAt (line 997)

Sets up a trigger to throw an exception upon the method call.

void throwAt ( $timing,  $method, [ $exception = false], [ $args = false])
  • $timing
  • $method
  • $exception
  • $args
throwOn (line 987)

Sets up a trigger to throw an exception upon the method call.

void throwOn (string $method, [ $exception = false], [ $args = false])
  • string $method: Method name to throw on.
  • $exception
  • $args
_addCall (line 741)

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.
_dieOnNoMethod (line 707)

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.
_emulateCall (line 1077)

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.
_getCurrentTestCase (line 680)

Finds currently running test.

  • return: Current test case.
  • access: protected
SimpeTestCase &_getCurrentTestCase ()

Documentation generated on Sun, 04 May 2008 09:21:48 -0500 by phpDocumentor 1.3.0