[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/tests_runner/lib/simpletest/ -> mock_objects.php (summary)

base include file for SimpleTest

Version: $Id: mock_objects.php 5999 2007-06-18 13:13:08Z pachanga $
File Size: 1306 lines (55 kb)
Included or required: 1 time
Referenced: 0 times
Includes or requires: 0 files

Defines 9 classes

ParametersExpectation:: (7 methods):
  ParametersExpectation()
  test()
  _testParameter()
  testMessage()
  _describeDifference()
  _coerceToExpectation()
  _renderArguments()

CallCountExpectation:: (3 methods):
  CallCountExpectation()
  test()
  testMessage()

MinimumCallCountExpectation:: (3 methods):
  MinimumCallCountExpectation()
  test()
  testMessage()

MaximumCallCountExpectation:: (3 methods):
  MaximumCallCountExpectation()
  test()
  testMessage()

CallMap:: (6 methods):
  CallMap()
  addValue()
  addReference()
  findFirstMatch()
  isMatch()
  _findFirstSlot()

SimpleMock:: (27 methods):
  SimpleMock()
  disableExpectationNameChecks()
  _getCurrentTestCase()
  _checkArgumentsIsArray()
  _dieOnNoMethod()
  _replaceWildcards()
  _addCall()
  getCallCount()
  setReturnValue()
  setReturnValueAt()
  setReturnReference()
  setReturnReferenceAt()
  expect()
  expectArguments()
  expectAt()
  expectArgumentsAt()
  expectCallCount()
  expectMaximumCallCount()
  expectMinimumCallCount()
  expectNever()
  expectOnce()
  expectAtLeastOnce()
  tally()
  atTestEnd()
  _invoke()
  _getReturn()
  _checkExpectations()

Mock:: (4 methods):
  Mock()
  generate()
  generatePartial()
  getExpectationLine()

Stub:: (0 methods):

MockGenerator:: (15 methods):
  MockGenerator()
  generate()
  generateSubclass()
  generatePartial()
  _createClassCode()
  _createSubclassCode()
  _extendClassCode()
  _createHandlerCode()
  _createNewMethodCode()
  _isConstructor()
  _addMethodList()
  _bailOutIfNotMocked()
  _chainMockReturns()
  _chainMockExpectations()
  _overrideMethods()


Class: ParametersExpectation  - X-Ref

Parameter comparison assertion.

ParametersExpectation($expected = false, $message = '%s')   X-Ref
Sets the expected parameter list.

param: array $parameters  Array of parameters including
param: string $message    Customised message on failure.

test($parameters)   X-Ref
Tests the assertion. True if correct.

param: array $parameters     Comparison values.
return: boolean              True if correct.

_testParameter($parameter, $expected)   X-Ref
Tests an individual parameter.

param: mixed $parameter    Value to test.
param: mixed $expected     Comparison value.
return: boolean            True if expectation

testMessage($parameters)   X-Ref
Returns a human readable test message.

param: array $comparison   Incoming parameter list.
return: string             Description of success

_describeDifference($expected, $parameters)   X-Ref
Message to display if expectation differs from
the parameters actually received.

param: array $expected      Expected parameters as list.
param: array $parameters    Actual parameters received.
return: string              Description of difference.

_coerceToExpectation($expected)   X-Ref
Creates an identical expectation if the
object/value is not already some type
of expectation.

param: mixed $expected      Expected value.
return: SimpleExpectation   Expectation object.

_renderArguments($args)   X-Ref
Renders the argument list as a string for
messages.

param: array $args    Incoming arguments.
return: string        Simple description of type and value.

Class: CallCountExpectation  - X-Ref

Confirms that the number of calls on a method is as expected.

CallCountExpectation($method, $count, $message = '%s')   X-Ref
Stashes the method and expected count for later
reporting.

param: string $method    Name of method to confirm against.
param: integer $count    Expected number of calls.
param: string $message   Custom error message.

test($compare)   X-Ref
Tests the assertion. True if correct.

param: integer $compare     Measured call count.
return: boolean             True if expected.

testMessage($compare)   X-Ref
Reports the comparison.

param: integer $compare     Measured call count.
return: string              Message to show.

Class: MinimumCallCountExpectation  - X-Ref

Confirms that the number of calls on a method is as expected.

MinimumCallCountExpectation($method, $count, $message = '%s')   X-Ref
Stashes the method and expected count for later
reporting.

param: string $method    Name of method to confirm against.
param: integer $count    Minimum number of calls.
param: string $message   Custom error message.

test($compare)   X-Ref
Tests the assertion. True if correct.

param: integer $compare     Measured call count.
return: boolean             True if enough.

testMessage($compare)   X-Ref
Reports the comparison.

param: integer $compare     Measured call count.
return: string              Message to show.

Class: MaximumCallCountExpectation  - X-Ref

Confirms that the number of calls on a method is as expected.

MaximumCallCountExpectation($method, $count, $message = '%s')   X-Ref
Stashes the method and expected count for later
reporting.

param: string $method    Name of method to confirm against.
param: integer $count    Minimum number of calls.
param: string $message   Custom error message.

test($compare)   X-Ref
Tests the assertion. True if correct.

param: integer $compare     Measured call count.
return: boolean             True if not over.

testMessage($compare)   X-Ref
Reports the comparison.

param: integer $compare     Measured call count.
return: string              Message to show.

Class: CallMap  - X-Ref

Retrieves values and references by searching the
parameter lists until a match is found.

CallMap()   X-Ref
Creates an empty call map.


addValue($parameters, $value)   X-Ref
Stashes a value against a method call.

param: array $parameters    Arguments including wildcards.
param: mixed $value         Value copied into the map.

addReference($parameters, &$reference)   X-Ref
Stashes a reference against a method call.

param: array $parameters    Array of arguments (including wildcards).
param: mixed $reference     Array reference placed in the map.

findFirstMatch($parameters)   X-Ref
Searches the call list for a matching parameter
set. Returned by reference.

param: array $parameters    Parameters to search by
return: object              Object held in the first matching

isMatch($parameters)   X-Ref
Searches the call list for a matching parameter
set. True if successful.

param: array $parameters    Parameters to search by
return: boolean             True if a match is present.

_findFirstSlot($parameters)   X-Ref
Searches the map for a matching item.

param: array $parameters    Parameters to search by
return: array               Reference to slot or null.

Class: SimpleMock  - X-Ref

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.

SimpleMock()   X-Ref
Creates an empty return list and expectation list.
All call counts are set to zero.


disableExpectationNameChecks()   X-Ref
Disables a name check when setting expectations.
This hack is needed for the partial mocks.


_getCurrentTestCase()   X-Ref
Finds currently running test.

return: SimpeTestCase    Current test case.

_checkArgumentsIsArray($args, $task)   X-Ref
Die if bad arguments array is passed

param: mixed $args     The arguments value to be checked.
param: string $task    Description of task attempt.
return: boolean        Valid arguments

_dieOnNoMethod($method, $task)   X-Ref
Triggers a PHP error if the method is not part
of this object.

param: string $method        Name of method.
param: string $task          Description of task attempt.

_replaceWildcards($args)   X-Ref
Replaces wildcard matches with wildcard
expectations in the argument list.

param: array $args      Raw argument list.
return: array           Argument list with

_addCall($method, $args)   X-Ref
Adds one to the call count of a method.

param: string $method        Method called.
param: array $args           Arguments as an array.

getCallCount($method)   X-Ref
Fetches the call count of a method so far.

param: string $method        Method name called.
return: Number of calls so far.

setReturnValue($method, $value, $args = false)   X-Ref
Sets a return for a parameter list that will
be passed by value for all calls to this method.

param: string $method       Method name.
param: mixed $value         Result of call passed by value.
param: array $args          List of parameters to match

setReturnValueAt($timing, $method, $value, $args = false)   X-Ref
Sets a return for a parameter list that will
be passed by value only when the required call count
is reached.

param: integer $timing   Number of calls in the future
param: string $method    Method name.
param: mixed $value      Result of call passed by value.
param: array $args       List of parameters to match

setReturnReference($method, &$reference, $args = false)   X-Ref
Sets a return for a parameter list that will
be passed by reference for all calls.

param: string $method       Method name.
param: mixed $reference     Result of the call will be this object.
param: array $args          List of parameters to match

setReturnReferenceAt($timing, $method, &$reference, $args = false)   X-Ref
Sets a return for a parameter list that will
be passed by value only when the required call count
is reached.

param: integer $timing    Number of calls in the future
param: string $method     Method name.
param: mixed $reference   Result of the call will be this object.
param: array $args        List of parameters to match

expect($method, $args, $message = '%s')   X-Ref
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.

param: string $method        Method call to test.
param: array $args           Expected parameters for the call
param: string $message       Overridden message.

expectArguments($method, $args, $message = '%s')   X-Ref


expectAt($timing, $method, $args, $message = '%s')   X-Ref
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.

param: integer $timing    Number of calls in the future at
param: string $method     Method call to test.
param: array $args        Expected parameters for the call
param: string $message    Overridden message.

expectArgumentsAt($timing, $method, $args, $message = '%s')   X-Ref


expectCallCount($method, $count, $message = '%s')   X-Ref
Sets an expectation for the number of times
a method will be called. The tally method
is used to check this.

param: string $method        Method call to test.
param: integer $count        Number of times it should
param: string $message       Overridden message.

expectMaximumCallCount($method, $count, $message = '%s')   X-Ref
Sets the number of times a method may be called
before a test failure is triggered.

param: string $method        Method call to test.
param: integer $count        Most number of times it should
param: string $message       Overridden message.

expectMinimumCallCount($method, $count, $message = '%s')   X-Ref
Sets the number of times to call a method to prevent
a failure on the tally.

param: string $method      Method call to test.
param: integer $count      Least number of times it should
param: string $message     Overridden message.

expectNever($method, $message = '%s')   X-Ref
Convenience method for barring a method
call.

param: string $method        Method call to ban.
param: string $message       Overridden message.

expectOnce($method, $args = false, $message = '%s')   X-Ref
Convenience method for a single method
call.

param: string $method     Method call to track.
param: array $args        Expected argument list or
param: string $message    Overridden message.

expectAtLeastOnce($method, $args = false, $message = '%s')   X-Ref
Convenience method for requiring a method
call.

param: string $method       Method call to track.
param: array $args          Expected argument list or
param: string $message      Overridden message.

tally()   X-Ref


atTestEnd($test_method, &$test)   X-Ref
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.

param: string $test_method      Current method name.
param: SimpleTestCase $test     Test to send message to.

_invoke($method, $args)   X-Ref
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.

param: string $method       Name of method to simulate.
param: array $args          Arguments as an array.
return: mixed               Stored return.

_getReturn($method, $args, $step)   X-Ref
Finds the return value matching the incoming
arguments. If there is no matching value found
then an error is triggered.

param: string $method      Method name.
param: array $args         Calling arguments.
param: integer $step       Current position in the
return: mixed              Stored return.

_checkExpectations($method, $args, $timing)   X-Ref
Tests the arguments against expectations.

param: string $method        Method to check.
param: array $args           Argument list to match.
param: integer $timing       The position of this call

Class: Mock  - X-Ref

Static methods only service class for code generation of
mock objects.

Mock()   X-Ref
Factory for mock object classes.


generate($class, $mock_class = false, $methods = false)   X-Ref
Clones a class' interface and creates a mock version
that can have return values and expectations set.

param: string $class         Class to clone.
param: string $mock_class    New class name. Default is
param: array $methods        Additional methods to add beyond

generatePartial($class, $mock_class, $methods)   X-Ref
Generates a version of a class with selected
methods mocked only. Inherits the old class
and chains the mock methods of an aggregated
mock object.

param: string $class            Class to clone.
param: string $mock_class       New class name.
param: array $methods           Methods to be overridden

getExpectationLine()   X-Ref
Uses a stack trace to find the line of an assertion.


Class: Stub  - X-Ref


Class: MockGenerator  - X-Ref

Service class for code generation of mock objects.

MockGenerator($class, $mock_class)   X-Ref
Builds initial reflection object.

param: string $class        Class to be mocked.
param: string $mock_class   New class with identical interface,

generate($methods)   X-Ref
Clones a class' interface and creates a mock version
that can have return values and expectations set.

param: array $methods        Additional methods to add beyond

generateSubclass($methods)   X-Ref
Subclasses a class and overrides every method with a mock one
that can have return values and expectations set. Chains
to an aggregated SimpleMock.

param: array $methods        Additional methods to add beyond

generatePartial($methods)   X-Ref
Generates a version of a class with selected
methods mocked only. Inherits the old class
and chains the mock methods of an aggregated
mock object.

param: array $methods           Methods to be overridden

_createClassCode($methods)   X-Ref
The new mock class code as a string.

param: array $methods          Additional methods.
return: string                 Code for new mock class.

_createSubclassCode($methods)   X-Ref
The new mock class code as a string. The mock will
be a subclass of the original mocked class.

param: array $methods          Additional methods.
return: string                 Code for new mock class.

_extendClassCode($methods)   X-Ref
The extension class code as a string. The class
composites a mock object and chains mocked methods
to it.

param: array  $methods       Mocked methods.
return: string               Code for a new class.

_createHandlerCode($methods)   X-Ref
Creates code within a class to generate replaced
methods. All methods call the _invoke() handler
with the method name and the arguments in an
array.

param: array $methods    Additional methods.

_createNewMethodCode($methods)   X-Ref
Creates code within a class to generate a new
methods. All methods call the _invoke() handler
on the internal mock with the method name and
the arguments in an array.

param: array $methods    Additional methods.

_isConstructor($method)   X-Ref
Tests to see if a special PHP method is about to
be stubbed by mistake.

param: string $method    Method name.
return: boolean          True if special.

_addMethodList($methods)   X-Ref
Creates a list of mocked methods for error checking.

param: array $methods       Mocked methods.
return: string              Code for a method list.

_bailOutIfNotMocked($alias)   X-Ref
Creates code to abandon the expectation if not mocked.

param: string $alias       Parameter name of method name.
return: string             Code for bail out.

_chainMockReturns()   X-Ref
Creates source code for chaining to the composited
mock object.

return: string           Code for mock set up.

_chainMockExpectations()   X-Ref
Creates source code for chaining to an aggregated
mock object.

return: string                 Code for expectations.

_overrideMethods($methods)   X-Ref
Creates source code to override a list of methods
with mock versions.

param: array $methods    Methods to be overridden
return: string           Code for overridden chains.



Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7