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 1953 2009-09-20 01:26:25Z jsweat $
* 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');
* 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.
function __construct($expected =
false, $message =
'%s') {
$this->expected =
$expected;
* Tests the assertion. True if correct.
* @param array $parameters Comparison values.
* @return boolean True if correct.
function test($parameters) {
if (count($this->expected) !=
count($parameters)) {
for ($i =
0; $i <
count($this->expected); $i++
) {
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
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)) {
return "Expectation of " .
count($this->expected) .
* 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.
return "Expected " .
count($expected) .
"] but got " .
count($parameters) .
for ($i =
0; $i <
count($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.
* Renders the argument list as a string for
* @param array $args Incoming arguments.
* @return string Simple description of type and value.
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.
function __construct($method, $count, $message =
'%s') {
* 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 .
'] was [' .
$this->count .
'] 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.
function __construct($method, $count, $message =
'%s') {
* 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 .
'] was [' .
$this->count .
'] 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.
function __construct($method, $count, $message =
'%s') {
* 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 .
'] was [' .
$this->count .
'] 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) {
$place =
count($this->map);
$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) {
$count =
count($this->map);
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
private $wildcard =
MOCK_ANYTHING;
* 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) {
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) {
if (! isset
($this->at[$method])) {
$this->at[$method] =
array();
if (! isset
($this->at[$method][$step])) {
$this->at[$method][$step]->add($args, $action);
* Sets up an expectation on the argument list.
* @param string $method Method to test.
* @param array $args Bare arguments or list of
* @param string $message Failure message.
* 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
for ($i =
0; $i <
count($args); $i++
) {
if ($args[$i] ===
$this->wildcard) {
* A type of SimpleMethodAction.
* Stashes a value for returning later. Follows usual
* PHP5 semantics of objects being returned by reference.
* @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 a reference for returning later.
* @subpackage MockObjects
* @param mixed $reference Actual PHP4 style reference.
$this->reference =
&$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.
$this->exception =
$exception;
* Throws the exceptins stashed earlier.
* 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.
$this->severity =
$severity;
* Triggers the stashed error.
* 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
private $wildcard =
MOCK_ANYTHING;
private $is_strict =
true;
private $expected_counts;
private $expected_args_at;
* Creates an empty action list and expectation list.
* All call counts are set to zero.
$this->call_counts =
array();
$this->expected_counts =
array();
$this->max_counts =
array();
$this->expected_args =
array();
$this->expected_args_at =
array();
* Disables a name check when setting expectations.
* This hack is needed for the partial mocks.
$this->is_strict =
false;
* Finds currently running test.
* @return SimpeTestCase Current test case.
* 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
"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++
) {
if ($args[$i] ===
$this->wildcard) {
* Adds one to the call count of a method.
* @param string $method Method called.
* @param array $args Arguments as an array.
protected function addCall($method, $args) {
if (! isset
($this->call_counts[$method])) {
$this->call_counts[$method] =
0;
$this->call_counts[$method]++
;
* Fetches the call count of a method so far.
* @param string $method Method name called.
* @return integer Number of calls so far.
if (! isset
($this->call_counts[$method])) {
return $this->call_counts[$method];
* Sets a return for a parameter list that will
* be passed on by all calls to this method that match.
* @param string $method Method name.
* @param mixed $value Result of call by value/handle.
* @param array $args List of parameters to match
function returns($method, $value, $args =
false) {
$this->actions->register($method, $args, new SimpleReturn($value));
* Sets a return for a parameter list that will
* be passed 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.
* @param array $args List of parameters to match
function returnsAt($timing, $method, $value, $args =
false) {
$this->actions->registerAt($timing, $method, $args, new SimpleReturn($value));
* 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
$this->actions->register($method, $args, new SimpleByValue($value));
* 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
$this->actions->registerAt($timing, $method, $args, new SimpleByValue($value));
* 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
$this->actions->registerAt($timing, $method, $args, new SimpleByReference($reference));
* 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->expectations->expectArguments($method, $args, $message);
$args =
$this->replaceWildcards($args);
* 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') {
$args =
$this->replaceWildcards($args);
if (! isset
($this->expected_args_at[$timing])) {
$this->expected_args_at[$timing] =
array();
$this->expected_args_at[$timing][$method] =
* 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) {
$this->actions->registerAt($timing, $method, $args, new SimpleErrorThrower($error, $severity));
* 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->expected_counts as $method =>
$expectation) {
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) {
$was =
$this->disableEStrict();
$this->restoreEStrict($was);
$this->restoreEStrict($was);
* 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.
protected function &emulateCall($method, $args, $step) {
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
if (isset
($this->max_counts[$method])) {
if (! $this->max_counts[$method]->test($timing +
1)) {
$test->assert($this->max_counts[$method], $timing +
1);
if (isset
($this->expected_args_at[$timing][$method])) {
$this->expected_args_at[$timing][$method],
"Mock method [$method] at [$timing] -> %s");
} elseif (isset
($this->expected_args[$method])) {
$this->expected_args[$method],
"Mock method [$method] -> %s");
private function disableEStrict() {
private function restoreEStrict($was) {
* 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.sta
static 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();
* 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,
$this->mock_class =
$mock_class;
if (! $this->mock_class) {
$this->mock_class =
'Mock' .
$this->class;
* 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 (! $this->reflection->classOrInterfaceExists()) {
if ($mock_reflection->classExistsSansAutoload()) {
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 (! $this->reflection->classOrInterfaceExists()) {
if ($mock_reflection->classExistsSansAutoload()) {
if ($this->reflection->isInterface() ||
$this->reflection->hasFinal()) {
return eval
("$code return \$code;");
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 (! $this->reflection->classExists($this->class)) {
if ($mock_reflection->classExistsSansAutoload()) {
trigger_error('Partial mock class [' .
$this->mock_class .
'] already exists');
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.
$interfaces =
$this->reflection->getInterfaces();
$interfaces =
array_diff($interfaces, array('Traversable'));
if (count($interfaces) >
0) {
$implements =
'implements ' .
implode(', ', $interfaces);
$code =
"class " .
$this->mock_class .
" extends " .
$this->mock_base .
" $implements {\n";
$code .=
" function " .
$this->mock_class .
"() {\n";
$code .=
" \$this->" .
$this->mock_base .
"();\n";
if (in_array('__construct', $this->reflection->getMethods())) {
$code .=
" function __construct() {\n";
$code .=
" \$this->" .
$this->mock_base .
"();\n";
* 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.
$code =
"class " .
$this->mock_class .
" extends " .
$this->class .
" {\n";
$code .=
" public \$mock;\n";
$code .=
" function " .
$this->mock_class .
"() {\n";
$code .=
" \$this->mock = new " .
$this->mock_base .
"();\n";
$code .=
" \$this->mock->disableExpectationNameChecks();\n";
* 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.
$code =
"class " .
$this->mock_class .
" extends " .
$this->class .
" {\n";
$code .=
" protected \$mock;\n";
$code .=
" function " .
$this->mock_class .
"() {\n";
$code .=
" \$this->mock = new " .
$this->mock_base .
"();\n";
$code .=
" \$this->mock->disableExpectationNameChecks();\n";
* 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.
$methods =
array_merge($methods, $this->reflection->getMethods());
foreach ($methods as $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.
foreach ($methods as $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.
array('__construct', '__destruct'));
* Creates a list of mocked methods for error checking.
* @param array $methods Mocked methods.
* @return string Code for a method list.
return " protected \$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.
$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.
$code =
" function returns(\$method, \$value, \$args = false) {\n";
$code .=
" \$this->mock->returns(\$method, \$value, \$args);\n";
$code .=
" function returnsAt(\$timing, \$method, \$value, \$args = false) {\n";
$code .=
" \$this->mock->returnsAt(\$timing, \$method, \$value, \$args);\n";
$code .=
" function returnsByValue(\$method, \$value, \$args = false) {\n";
$code .=
" \$this->mock->setReturnValue(\$method, \$value, \$args);\n";
$code .=
" function returnsByValueAt(\$timing, \$method, \$value, \$args = false) {\n";
$code .=
" \$this->mock->setReturnValueAt(\$timing, \$method, \$value, \$args);\n";
$code .=
" function returnsByReference(\$method, &\$ref, \$args = false) {\n";
$code .=
" \$this->mock->setReturnReference(\$method, \$ref, \$args);\n";
$code .=
" function returnsByReferenceAt(\$timing, \$method, &\$ref, \$args = false) {\n";
$code .=
" \$this->mock->setReturnReferenceAt(\$timing, \$method, \$ref, \$args);\n";
$code .=
" function setReturnValue(\$method, \$value, \$args = false) {\n";
$code .=
" \$this->mock->setReturnValue(\$method, \$value, \$args);\n";
$code .=
" function setReturnValueAt(\$timing, \$method, \$value, \$args = false) {\n";
$code .=
" \$this->mock->setReturnValueAt(\$timing, \$method, \$value, \$args);\n";
$code .=
" function setReturnReference(\$method, &\$ref, \$args = false) {\n";
$code .=
" \$this->mock->setReturnReference(\$method, \$ref, \$args);\n";
$code .=
" function setReturnReferenceAt(\$timing, \$method, &\$ref, \$args = false) {\n";
$code .=
" \$this->mock->setReturnReferenceAt(\$timing, \$method, \$ref, \$args);\n";
* Creates source code for chaining to an aggregated
* @return string Code for expectations.
$code =
" function expect(\$method, \$args = false, \$msg = '%s') {\n";
$code .=
" \$this->mock->expect(\$method, \$args, \$msg);\n";
$code .=
" function expectAt(\$timing, \$method, \$args = false, \$msg = '%s') {\n";
$code .=
" \$this->mock->expectAt(\$timing, \$method, \$args, \$msg);\n";
$code .=
" function expectCallCount(\$method, \$count) {\n";
$code .=
" \$this->mock->expectCallCount(\$method, \$count, \$msg = '%s');\n";
$code .=
" function expectMaximumCallCount(\$method, \$count, \$msg = '%s') {\n";
$code .=
" \$this->mock->expectMaximumCallCount(\$method, \$count, \$msg = '%s');\n";
$code .=
" function expectMinimumCallCount(\$method, \$count, \$msg = '%s') {\n";
$code .=
" \$this->mock->expectMinimumCallCount(\$method, \$count, \$msg = '%s');\n";
$code .=
" function expectNever(\$method) {\n";
$code .=
" \$this->mock->expectNever(\$method);\n";
$code .=
" function expectOnce(\$method, \$args = false, \$msg = '%s') {\n";
$code .=
" \$this->mock->expectOnce(\$method, \$args, \$msg);\n";
$code .=
" function expectAtLeastOnce(\$method, \$args = false, \$msg = '%s') {\n";
$code .=
" \$this->mock->expectAtLeastOnce(\$method, \$args, \$msg);\n";
* Adds code for chaining the throw methods.
* @return string Code for chains.
$code =
" function throwOn(\$method, \$exception = false, \$args = false) {\n";
$code .=
" \$this->mock->throwOn(\$method, \$exception, \$args);\n";
$code .=
" function throwAt(\$timing, \$method, \$exception = false, \$args = false) {\n";
$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->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->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.
foreach ($methods as $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 Thu, 01 Oct 2009 20:55:11 -0500 by phpDocumentor 1.4.2