Class SimpleMock

Description

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.

Located in /libraries/pear/simpletest/mock_objects.php (line 526)

SimpleStub
   |
   --SimpleMock
Direct descendents
Class Description
 class SpecialSimpleMock An empty collection of methods that can have their
Variable Summary
Method Summary
 SimpleMock SimpleMock (SimpleTestCase &$test, mixed $wildcard, [boolean $is_strict = true])
 void expectArguments (string $method, array $args)
 void expectArgumentsAt (integer $timing, string $method, array $args)
 void expectAtLeastOnce (string $method, [array $args = false])
 void expectCallCount (string $method, integer $count)
 void expectMaximumCallCount (string $method, integer $count)
 void expectMinimumCallCount (string $method, integer $count)
 void expectNever (string $method)
 void expectOnce (string $method, [array $args = false])
 void tally ()
 void _assertTrue (boolean $assertion, string $message, SimpleTestCase &$test)
 boolean _CheckArgumentsArray (mixed $args, string $task)
 void _checkExpectations (string $method, array $args, integer $timing)
 mixed &_invoke (string $method, array $args)
 void _warnOnNoReturn (mixed $method)
Variables
mixed $_expected_args (line 531)
mixed $_expected_args_at (line 532)
mixed $_expected_counts (line 528)
mixed $_max_counts (line 529)
mixed $_min_counts (line 530)
mixed $_require_return (line 533)
mixed $_test (line 527)

Inherited Variables

Inherited from SimpleStub

SimpleStub::$_call_counts
SimpleStub::$_is_strict
SimpleStub::$_returns
SimpleStub::$_return_sequence
SimpleStub::$_wildcard
Methods
Constructor SimpleMock (line 544)

Creates an empty return list and expectation list.

All call counts are set to zero.

  • access: public
SimpleMock SimpleMock (SimpleTestCase &$test, mixed $wildcard, [boolean $is_strict = true])
  • SimpleTestCase $test: Test case to test expectations in.
  • mixed $wildcard: Parameter matching wildcard.
  • boolean $is_strict: Enables method name checks on expectations.
expectArguments (line 594)

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 expectArguments (string $method, array $args)
  • string $method: Method call to test.
  • array $args: Expected parameters for the call including wildcards.
expectArgumentsAt (line 614)

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 expectArgumentsAt (integer $timing, string $method, array $args)
  • 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.
expectAtLeastOnce (line 699)

Convenience method for requiring a method call.

  • access: public
void expectAtLeastOnce (string $method, [array $args = false])
  • string $method: Method call to track.
  • array $args: Expected argument list or false for any arguments.
expectCallCount (line 635)

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 $method: Method call to test.
  • integer $count: Number of times it should have been called at tally.
expectMaximumCallCount (line 648)

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 $method: Method call to test.
  • integer $count: Most number of times it should have been called.
expectMinimumCallCount (line 661)

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 $method: Method call to test.
  • integer $count: Least number of times it should have been called.
expectNever (line 672)

Convenience method for barring a method call.

  • access: public
void expectNever (string $method)
  • string $method: Method call to ban.
expectOnce (line 684)

Convenience method for a single method call.

  • access: public
void expectOnce (string $method, [array $args = false])
  • string $method: Method call to track.
  • array $args: Expected argument list or false for any arguments.
getTest (line 565)

Accessor for attached unit test so that when subclassed, new expectations can be added easily.

  • return: Unit test passed in constructor.
  • access: public
SimpleTestCase &getTest ()
tally (line 714)

Totals up the call counts and triggers a test assertion if a test is present for expected call counts.

This method must be called explicitly for the call count assertions to be triggered.

  • access: public
void tally ()
_assertTrue (line 816)

Triggers an assertion on the held test case.

Should be overridden when using another test framework other than the SimpleTest one if the assertion method has a different name.

  • access: protected
void _assertTrue (boolean $assertion, string $message, SimpleTestCase &$test)
  • boolean $assertion: True will pass.
  • string $message: Message that will go with the test event.
  • SimpleTestCase $test: Unit test case to send assertion to.
_CheckArgumentsArray (line 576)

Die if bad arguments array is passed

  • return: Valid arguments
  • access: private
boolean _CheckArgumentsArray (mixed $args, string $task)
  • mixed $args: The arguments value to be checked.
  • string $task: Description of task attempt.
_checkExpectations (line 771)

Tests the arguments against expectations.

  • access: private
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.
_invoke (line 755)

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.
  • access: private
mixed &_invoke (string $method, array $args)
  • string $method: Name of method to simulate.
  • array $args: Arguments as an array.

Redefinition of:
SimpleStub::_invoke()
Returns the expected value for the method name.
_tally_call_counts (line 723)

Checks that the exact call counts match up.

  • access: private
void _tally_call_counts ()
_tally_minimum_call_counts (line 736)

Checks that the minimum call counts match up.

  • access: private
void _tally_minimum_call_counts ()
_warnOnNoReturn (line 796)
  • deprecated:
void _warnOnNoReturn (mixed $method)

Redefinition of:
SimpleStub::_warnOnNoReturn()
What to do if there is no return value set. Does nothing for a stub.

Inherited Methods

Inherited From SimpleStub

 SimpleStub::SimpleStub()
 SimpleStub::clearHistory()
 SimpleStub::getCallCount()
 SimpleStub::setReturnReference()
 SimpleStub::setReturnReferenceAt()
 SimpleStub::setReturnValue()
 SimpleStub::setReturnValueAt()
 SimpleStub::_addCall()
 SimpleStub::_dieOnNoMethod()
 SimpleStub::_getReturn()
 SimpleStub::_invoke()
 SimpleStub::_replaceWildcards()
 SimpleStub::_warnOnNoReturn()

Documentation generated on Thu, 20 Jan 2005 17:10:16 +0000 by phpDocumentor 1.3.0RC3