Source for file mock_objects.php
Documentation is available at mock_objects.php
* base include file for SimpleTest
* @subpackage MockObjects
* @version $Id: mock_objects.php 1672 2008-03-02 04:47:34Z edwardzyang $
* include SimpleTest files
require_once(dirname(__FILE__
) .
'/expectation.php');
require_once(dirname(__FILE__
) .
'/simpletest.php');
require_once(dirname(__FILE__
) .
'/dumper.php');
require_once(dirname(__FILE__
) .
'/reflection_php5.php');
require_once(dirname(__FILE__
) .
'/reflection_php4.php');
* Default character simpletest will substitute for any value
* Parameter comparison assertion.
* @subpackage MockObjects
* Sets the expected parameter list.
* @param array $parameters Array of parameters including
* those that are wildcarded.
* If the value is not an array
* then it is considered to match any.
* @param string $message Customised message on failure.
* Tests the assertion. True if correct.
* @param array $parameters Comparison values.
* @return boolean True if correct.
function test($parameters) {
if (! $this->_testParameter($parameters[$i], $this->_expected[$i])) {
* Tests an individual parameter.
* @param mixed $parameter Value to test.
* @param mixed $expected Comparison value.
* @return boolean True if expectation
function _testParameter($parameter, $expected) {
$comparison =
$this->_coerceToExpectation($expected);
return $comparison->test($parameter);
* Returns a human readable test message.
* @param array $comparison Incoming parameter list.
* @return string Description of success
if ($this->test($parameters)) {
" arguments of [" .
$this->_renderArguments($this->_expected) .
return $this->_describeDifference($this->_expected, $parameters);
* 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.
function _describeDifference($expected, $parameters) {
return "Expected " .
count($expected) .
" arguments of [" .
$this->_renderArguments($expected) .
"] but got " .
count($parameters) .
" arguments of [" .
$this->_renderArguments($parameters) .
"]";
for ($i =
0; $i <
count($expected); $i++
) {
$comparison =
$this->_coerceToExpectation($expected[$i]);
if (! $comparison->test($parameters[$i])) {
$messages[] =
"parameter " .
($i +
1) .
" with [" .
$comparison->overlayMessage($parameters[$i], $this->_getDumper()) .
"]";
return "Parameter expectation differs at " .
implode(" and ", $messages);
* Creates an identical expectation if the
* object/value is not already some type
* @param mixed $expected Expected value.
* @return SimpleExpectation Expectation object.
function _coerceToExpectation($expected) {
* Renders the argument list as a string for
* @param array $args Incoming arguments.
* @return string Simple description of type and value.
function _renderArguments($args) {
foreach ($args as $arg) {
$descriptions[] =
$dumper->describeValue($arg);
return implode(', ', $descriptions);
* Confirms that the number of calls on a method is as expected.
* @subpackage MockObjects
* Stashes the method and expected count for later
* @param string $method Name of method to confirm against.
* @param integer $count Expected number of calls.
* @param string $message Custom error message.
* Tests the assertion. True if correct.
* @param integer $compare Measured call count.
* @return boolean True if expected.
function test($compare) {
return ($this->_count ==
$compare);
* Reports the comparison.
* @param integer $compare Measured call count.
* @return string Message to show.
return 'Expected call count for [' .
$this->_method .
'] got [' .
$compare .
']';
* Confirms that the number of calls on a method is as expected.
* @subpackage MockObjects
* Stashes the method and expected count for later
* @param string $method Name of method to confirm against.
* @param integer $count Minimum number of calls.
* @param string $message Custom error message.
* Tests the assertion. True if correct.
* @param integer $compare Measured call count.
* @return boolean True if enough.
function test($compare) {
return ($this->_count <=
$compare);
* Reports the comparison.
* @param integer $compare Measured call count.
* @return string Message to show.
return 'Minimum call count for [' .
$this->_method .
'] got [' .
$compare .
']';
* Confirms that the number of calls on a method is as expected.
* @subpackage MockObjects
* Stashes the method and expected count for later
* @param string $method Name of method to confirm against.
* @param integer $count Minimum number of calls.
* @param string $message Custom error message.
* Tests the assertion. True if correct.
* @param integer $compare Measured call count.
* @return boolean True if not over.
function test($compare) {
return ($this->_count >=
$compare);
* Reports the comparison.
* @param integer $compare Measured call count.
* @return string Message to show.
return 'Maximum call count for [' .
$this->_method .
'] got [' .
$compare .
']';
* Retrieves method actions by searching the
* parameter lists until an expected match is found.
* @subpackage MockObjects
* Creates an empty call map.
* Stashes a reference against a method call.
* @param array $parameters Array of arguments (including wildcards).
* @param mixed $action Reference placed in the map.
function add($parameters, &$action) {
$this->_map[$place] =
array();
$this->_map[$place]['content'] =
&$action;
* 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
$slot =
$this->_findFirstSlot($parameters);
if (isset
($slot) && isset
($slot['content'])) {
* 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.
return ($this->_findFirstSlot($parameters) !=
null);
* Compares the incoming parameters with the
* internal expectation. Uses the incoming $test
* to dispatch the test message.
* @param SimpleTestCase $test Test to dispatch to.
* @param array $parameters The actual calling arguments.
* @param string $message The message to overlay.
function test(&$test, $parameters, $message) {
* Searches the map for a matching item.
* @param array $parameters Parameters to search by
* @return array Reference to slot or null.
function &_findFirstSlot($parameters) {
for ($i =
0; $i <
$count; $i++
) {
if ($this->_map[$i]["params"]->test($parameters)) {
* Allows setting of actions against call signatures either
* at a specific time, or always. Specific time settings
* trump lasting ones, otherwise the most recently added
* will mask an earlier match.
* @subpackage MockObjects
* Sets up an empty response schedule.
* Creates an empty call map.
* Stores an action against a signature that
* will always fire unless masked by a time
* @param string $method Method name.
* @param array $args Calling parameters.
* @param SimpleAction $action Actually simpleByValue, etc.
function register($method, $args, &$action) {
$args =
$this->_replaceWildcards($args);
if (! isset
($this->_always[$method])) {
$this->_always[$method]->add($args, $action);
* Stores an action against a signature that
* will fire at a specific time in the future.
* @param integer $step delay of calls to this method,
* @param string $method Method name.
* @param array $args Calling parameters.
* @param SimpleAction $action Actually SimpleByValue, etc.
function registerAt($step, $method, $args, &$action) {
$args =
$this->_replaceWildcards($args);
if (! isset
($this->_at[$method])) {
$this->_at[$method] =
array();
if (! isset
($this->_at[$method][$step])) {
$this->_at[$method][$step]->add($args, $action);
$args =
$this->_replaceWildcards($args);
* Actually carry out the action stored previously,
* if the parameters match.
* @param integer $step Time of call.
* @param string $method Method name.
* @param array $args The parameters making up the
* @return mixed The result of the action.
function &respond($step, $method, $args) {
if (isset
($this->_at[$method][$step])) {
if ($this->_at[$method][$step]->isMatch($args)) {
$action =
&$this->_at[$method][$step]->findFirstAction($args);
if (isset
($this->_always[$method])) {
$action =
&$this->_always[$method]->findFirstAction($args);
* Replaces wildcard matches with wildcard
* expectations in the argument list.
* @param array $args Raw argument list.
* @return array Argument list with
function _replaceWildcards($args) {
for ($i =
0; $i <
count($args); $i++
) {
* A type of SimpleMethodAction.
* Stashes a reference for returning later.
* @subpackage MockObjects
* @param mixed $reference Actual PHP4 style reference.
* Returns the reference stored earlier.
* @return mixed Whatever was stashed.
* A type of SimpleMethodAction.
* Stashes a value for returning later.
* @subpackage MockObjects
* @param mixed $value You need to clone objects
* if you want copy semantics
* Returns the value stored earlier.
* @return mixed Whatever was stashed.
* A type of SimpleMethodAction.
* Stashes an exception for throwing later.
* @subpackage MockObjects
* @param Exception $exception The exception object to throw.
* Throws the exceptins stashed earlier.
eval
('throw $this->_exception;');
* A type of SimpleMethodAction.
* Stashes an error for emitting later.
* @subpackage MockObjects
* Stashes an error to throw later.
* @param string $error Error message.
* @param integer $severity PHP error constant, e.g E_USER_ERROR.
* Triggers the stashed error.
* @return null The usual PHP4.4 shenanigans are needed here.
* 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.
* @subpackage MockObjects
* Creates an empty action list and expectation list.
* All call counts are set to zero.
* Disables a name check when setting expectations.
* This hack is needed for the partial mocks.
* Finds currently running test.
* @return SimpeTestCase Current test case.
return $context->getTest();
* 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
function _checkArgumentsIsArray($args, $task) {
"Cannot $task as \$args parameter is not an array",
* Triggers a PHP error if the method is not part
* @param string $method Name of method.
* @param string $task Description of task attempt.
"Cannot $task as no ${method}() in class " .
get_class($this),
* Replaces wildcard matches with wildcard
* expectations in the argument list.
* @param array $args Raw argument list.
* @return array Argument list with
function _replaceWildcards($args) {
for ($i =
0; $i <
count($args); $i++
) {
* Adds one to the call count of a method.
* @param string $method Method called.
* @param array $args Arguments as an array.
* Fetches the call count of a method so far.
* @param string $method Method name called.
* @return integer Number of calls so far.
* 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
* Sets a return for a parameter list that will
* be passed by value only when the required call count
* @param integer $timing Number of calls in the future
* to which the result applies. If
* not set then all calls will return
* @param string $method Method name.
* @param mixed $value Result of call passed by value.
* @param array $args List of parameters to match
* 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
* Sets a return for a parameter list that will
* be passed by value only when the required call count
* @param integer $timing Number of calls in the future
* to which the result applies. If
* not set then all calls will return
* @param string $method Method name.
* @param mixed $reference Result of the call will be this object.
* @param array $args List of parameters to match
* 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.
function expect($method, $args, $message =
'%s') {
$this->_checkArgumentsIsArray($args, 'set expected arguments');
$this->_expectations->expectArguments($method, $args, $message);
$args =
$this->_replaceWildcards($args);
return $this->expect($method, $args, $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.
* @param integer $timing Number of calls in the future at
* which to test. Next call is 0.
* @param string $method Method call to test.
* @param array $args Expected parameters for the call
* @param string $message Overridden message.
function expectAt($timing, $method, $args, $message =
'%s') {
$this->_checkArgumentsIsArray($args, 'set expected arguments at time');
$args =
$this->_replaceWildcards($args);
return $this->expectAt($timing, $method, $args, $message);
* Sets an expectation for the number of times
* a method will be called. The tally method
* @param string $method Method call to test.
* @param integer $count Number of times it should
* have been called at tally.
* @param string $message Overridden message.
* 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.
* 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.
* Convenience method for barring a method
* @param string $method Method call to ban.
* @param string $message Overridden message.
* Convenience method for a single method
* @param string $method Method call to track.
* @param array $args Expected argument list or
* false for any arguments.
* @param string $message Overridden message.
function expectOnce($method, $args =
false, $message =
'%s') {
$this->expect($method, $args, $message);
* Convenience method for requiring a method
* @param string $method Method call to track.
* @param array $args Expected argument list or
* false for any arguments.
* @param string $message Overridden message.
$this->expect($method, $args, $message);
* Sets up a trigger to throw an exception upon the
* @param string $method Method name to throw on.
function throwOn($method, $exception =
false, $args =
false) {
$this->_actions->register($method, $args,
* Sets up a trigger to throw an exception upon the
function throwAt($timing, $method, $exception =
false, $args =
false) {
$this->_actions->registerAt($timing, $method, $args,
* Sets up a trigger to throw an error upon the
function errorOn($method, $error =
'A mock error', $args =
false, $severity =
E_USER_ERROR) {
* Sets up a trigger to throw an error upon the
function errorAt($timing, $method, $error =
'A mock error', $args =
false, $severity =
E_USER_ERROR) {
* 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.
foreach ($this->_max_counts as $method =>
$expectation) {
* 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.
function &_invoke($method, $args) {
$this->_checkExpectations($method, $args, $step);
* 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 or other action.
return $this->_actions->respond($step, $method, $args);
* 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
function _checkExpectations($method, $args, $timing) {
if (! $this->_max_counts[$method]->test($timing +
1)) {
$test->assert($this->_max_counts[$method], $timing +
1);
"Mock method [$method] at [$timing] -> %s");
"Mock method [$method] -> %s");
* Static methods only service class for code generation of
* @subpackage MockObjects
* Factory for mock object classes.
* 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
* the old name with "Mock"
* @param array $methods Additional methods to add beyond
* those in the cloned class. Use this
* to emulate the dynamic addition of
* methods in the cloned class or when
* the class hasn't been written yet.
function generate($class, $mock_class =
false, $methods =
false) {
return $generator->generateSubclass($methods);
* Generates a version of a class with selected
* methods mocked only. Inherits the old class
* and chains the mock methods of an aggregated
* @param string $class Class to clone.
* @param string $mock_class New class name.
* @param array $methods Methods to be overridden
return $generator->generatePartial($methods);
* Uses a stack trace to find the line of an assertion.
return $trace->traceMethod();
* @subpackage MockObjects
* Service class for code generation of mock objects.
* @subpackage MockObjects
* Builds initial reflection object.
* @param string $class Class to be mocked.
* @param string $mock_class New class with identical interface,
* 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
* those in th cloned class. Use this
* to emulate the dynamic addition of
* methods in the cloned class or when
* the class hasn't been written yet.
if ($mock_reflection->classExistsSansAutoload()) {
$code =
$this->_createClassCode($methods ?
$methods :
array());
return eval
("$code return \$code;");
* 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
* those in the cloned class. Use this
* to emulate the dynamic addition of
* methods in the cloned class or when
* the class hasn't been written yet.
if ($mock_reflection->classExistsSansAutoload()) {
$code =
$this->_createClassCode($methods ?
$methods :
array());
return eval
("$code return \$code;");
$code =
$this->_createSubclassCode($methods ?
$methods :
array());
return eval
("$code return \$code;");
* Generates a version of a class with selected
* methods mocked only. Inherits the old class
* and chains the mock methods of an aggregated
* @param array $methods Methods to be overridden
if ($mock_reflection->classExistsSansAutoload()) {
$code =
$this->_extendClassCode($methods);
return eval
("$code return \$code;");
* The new mock class code as a string.
* @param array $methods Additional methods.
* @return string Code for new mock class.
function _createClassCode($methods) {
$interfaces =
array_diff($interfaces, array('Traversable'));
if (count($interfaces) >
0) {
$implements =
'implements ' .
implode(', ', $interfaces);
$code .=
" \$this->" .
$this->_mock_base .
"();\n";
$code .=
" " .
$this->_reflection->getSignature('__construct') .
" {\n";
$code .=
" \$this->" .
$this->_mock_base .
"();\n";
$code .=
$this->_createHandlerCode($methods);
* 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.
function _createSubclassCode($methods) {
$code .=
" var \$_mock;\n";
$code .=
" \$this->_mock = &new " .
$this->_mock_base .
"();\n";
$code .=
" \$this->_mock->disableExpectationNameChecks();\n";
$code .=
$this->_chainMockReturns();
$code .=
$this->_chainMockExpectations();
$code .=
$this->_chainThrowMethods();
$code .=
$this->_overrideMethods($this->_reflection->getMethods());
$code .=
$this->_createNewMethodCode($methods);
* The extension class code as a string. The class
* composites a mock object and chains mocked methods
* @param array $methods Mocked methods.
* @return string Code for a new class.
function _extendClassCode($methods) {
$code .=
" var \$_mock;\n";
$code .=
$this->_addMethodList($methods);
$code .=
" \$this->_mock = &new " .
$this->_mock_base .
"();\n";
$code .=
" \$this->_mock->disableExpectationNameChecks();\n";
$code .=
$this->_chainMockReturns();
$code .=
$this->_chainMockExpectations();
$code .=
$this->_chainThrowMethods();
$code .=
$this->_overrideMethods($methods);
* Creates code within a class to generate replaced
* methods. All methods call the _invoke() handler
* with the method name and the arguments in an
* @param array $methods Additional methods.
function _createHandlerCode($methods) {
foreach ($methods as $method) {
if ($this->_isConstructor($method)) {
if (in_array($method, $mock_reflection->getMethods())) {
$code .=
" " .
$this->_reflection->getSignature($method) .
" {\n";
$code .=
" \$args = func_get_args();\n";
$code .=
" \$result = &\$this->_invoke(\"$method\", \$args);\n";
$code .=
" return \$result;\n";
* 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.
function _createNewMethodCode($methods) {
foreach ($methods as $method) {
if ($this->_isConstructor($method)) {
if (in_array($method, $mock_reflection->getMethods())) {
$code .=
" " .
$this->_reflection->getSignature($method) .
" {\n";
$code .=
" \$args = func_get_args();\n";
$code .=
" \$result = &\$this->_mock->_invoke(\"$method\", \$args);\n";
$code .=
" return \$result;\n";
* Tests to see if a special PHP method is about to
* @param string $method Method name.
* @return boolean True if special.
function _isConstructor($method) {
array('__construct', '__destruct'));
* Creates a list of mocked methods for error checking.
* @param array $methods Mocked methods.
* @return string Code for a method list.
function _addMethodList($methods) {
return " var \$_mocked_methods = array('" .
* Creates code to abandon the expectation if not mocked.
* @param string $alias Parameter name of method name.
* @return string Code for bail out.
function _bailOutIfNotMocked($alias) {
$code =
" if (! in_array(strtolower($alias), \$this->_mocked_methods)) {\n";
$code .=
" trigger_error(\"Method [$alias] is not mocked\");\n";
$code .=
" \$null = null;\n";
$code .=
" return \$null;\n";
* Creates source code for chaining to the composited
* @return string Code for mock set up.
function _chainMockReturns() {
$code =
" function setReturnValue(\$method, \$value, \$args = false) {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->setReturnValue(\$method, \$value, \$args);\n";
$code .=
" function setReturnValueAt(\$timing, \$method, \$value, \$args = false) {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->setReturnValueAt(\$timing, \$method, \$value, \$args);\n";
$code .=
" function setReturnReference(\$method, &\$ref, \$args = false) {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->setReturnReference(\$method, \$ref, \$args);\n";
$code .=
" function setReturnReferenceAt(\$timing, \$method, &\$ref, \$args = false) {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->setReturnReferenceAt(\$timing, \$method, \$ref, \$args);\n";
* Creates source code for chaining to an aggregated
* @return string Code for expectations.
function _chainMockExpectations() {
$code =
" function expect(\$method, \$args = false, \$msg = '%s') {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->expect(\$method, \$args, \$msg);\n";
$code .=
" function expectArguments(\$method, \$args = false, \$msg = '%s') {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->expectArguments(\$method, \$args, \$msg);\n";
$code .=
" function expectAt(\$timing, \$method, \$args = false, \$msg = '%s') {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->expectArgumentsAt(\$timing, \$method, \$args, \$msg);\n";
$code .=
" function expectArgumentsAt(\$timing, \$method, \$args = false, \$msg = '%s') {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->expectArgumentsAt(\$timing, \$method, \$args, \$msg);\n";
$code .=
" function expectCallCount(\$method, \$count) {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->expectCallCount(\$method, \$count, \$msg = '%s');\n";
$code .=
" function expectMaximumCallCount(\$method, \$count, \$msg = '%s') {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->expectMaximumCallCount(\$method, \$count, \$msg = '%s');\n";
$code .=
" function expectMinimumCallCount(\$method, \$count, \$msg = '%s') {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->expectMinimumCallCount(\$method, \$count, \$msg = '%s');\n";
$code .=
" function expectNever(\$method) {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->expectNever(\$method);\n";
$code .=
" function expectOnce(\$method, \$args = false, \$msg = '%s') {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->expectOnce(\$method, \$args, \$msg);\n";
$code .=
" function expectAtLeastOnce(\$method, \$args = false, \$msg = '%s') {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->expectAtLeastOnce(\$method, \$args, \$msg);\n";
$code .=
" function tally() {\n";
* Adds code for chaining the throw methods.
* @return string Code for chains.
function _chainThrowMethods() {
$code =
" function throwOn(\$method, \$exception = false, \$args = false) {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->throwOn(\$method, \$exception, \$args);\n";
$code .=
" function throwAt(\$timing, \$method, \$exception = false, \$args = false) {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->throwAt(\$timing, \$method, \$exception, \$args);\n";
$code .=
" function errorOn(\$method, \$error = 'A mock error', \$args = false, \$severity = E_USER_ERROR) {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->errorOn(\$method, \$error, \$args, \$severity);\n";
$code .=
" function errorAt(\$timing, \$method, \$error = 'A mock error', \$args = false, \$severity = E_USER_ERROR) {\n";
$code .=
$this->_bailOutIfNotMocked("\$method");
$code .=
" \$this->_mock->errorAt(\$timing, \$method, \$error, \$args, \$severity);\n";
* Creates source code to override a list of methods
* @param array $methods Methods to be overridden
* @return string Code for overridden chains.
function _overrideMethods($methods) {
foreach ($methods as $method) {
if ($this->_isConstructor($method)) {
$code .=
" " .
$this->_reflection->getSignature($method) .
" {\n";
$code .=
" \$args = func_get_args();\n";
$code .=
" \$result = &\$this->_mock->_invoke(\"$method\", \$args);\n";
$code .=
" return \$result;\n";
Documentation generated on Sun, 04 May 2008 09:21:47 -0500 by phpDocumentor 1.3.0