intermediary commit of mock object madness

This commit is contained in:
tmont 2009-06-16 03:41:45 +00:00
parent d5134b4ec8
commit 65fba62f5d
5 changed files with 59 additions and 6 deletions

View File

@ -0,0 +1,17 @@
<?php
class InvocationTracker {
protected $invocations;
public function __construct() {
$this->invocations = array();
}
public function registerInvocation(MockInvocation $invocation) {
$this->invocations[] = $invocation;
}
}
?>

View File

@ -0,0 +1,23 @@
<?php
abstract class MockInvocation implements Verifiable {
protected $method;
protected $args;
public function __construct($methodName, array $args) {
$this->method = $methodName;
$this->args = $args;
}
public function getMethod() {
return $this->method;
}
public function getArgs() {
return $this->args;
}
}
?>

View File

@ -32,12 +32,12 @@
); );
} }
public static function registerInvocation($name, MockInvocation $invocation) { public static function registerInvocation($className, $methodName, array $args) {
if (!isset(self::$registry[$name])) { if (!isset(self::$registry[$className])) {
throw new LogicException('Unable to register invocation because the object does not exist in the registry'); throw new LogicException('Unable to register invocation because the object does not exist in the registry');
} }
self::$registry[$name]->registerInvocation($invocation); self::$registry[$className]->registerInvocation(new MockInvocation($methodName, $args));
} }
public static function getTracker($name) { public static function getTracker($name) {
@ -50,7 +50,6 @@
public function addMethod($methodName, $callParent = false, $body = '') { public function addMethod($methodName, $callParent = false, $body = '') {
$methodType = 'generic'; $methodType = 'generic';
if ($this->referenceObject->hasMethod($methodName)) { if ($this->referenceObject->hasMethod($methodName)) {
$method = $this->referenceObject->getMethod($methodName); $method = $this->referenceObject->getMethod($methodName);
if (!$this->methodIsMockable($method)) if (!$this->methodIsMockable($method))

View File

@ -0,0 +1,9 @@
<?php
interface Verifiable {
public function verify();
}
?>

View File

@ -3,7 +3,7 @@
/** /**
* Autoload manifest * Autoload manifest
* *
* Autogenerated by manifester.php on 2009-06-13 19:56:43 * Autogenerated by manifester.php on 2009-06-15 20:40:53
* *
* @package TUnit * @package TUnit
* @version 0.1.0 * @version 0.1.0
@ -30,7 +30,11 @@
'IdenticalConstraint' => 'TUnit/framework/constraints/IdenticalConstraint.php', 'IdenticalConstraint' => 'TUnit/framework/constraints/IdenticalConstraint.php',
'IgnoredTest' => 'TUnit/framework/result/FailedTest.php', 'IgnoredTest' => 'TUnit/framework/result/FailedTest.php',
'IgnoredTestResult' => 'TUnit/framework/result/IgnoredTestResult.php', 'IgnoredTestResult' => 'TUnit/framework/result/IgnoredTestResult.php',
'InvocationTracker' => 'TUnit/framework/mock/InvocationTracker.php',
'IssetConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php', 'IssetConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
'MockInvocation' => 'TUnit/framework/mock/MockInvocation.php',
'MockObject' => 'TUnit/framework/mock/MockObject.php',
'MockObjectCreator' => 'TUnit/framework/mock/MockObject.php',
'NotConstraint' => 'TUnit/framework/constraints/NotConstraint.php', 'NotConstraint' => 'TUnit/framework/constraints/NotConstraint.php',
'NullConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php', 'NullConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
'PassedTestResult' => 'TUnit/framework/result/PassedTestResult.php', 'PassedTestResult' => 'TUnit/framework/result/PassedTestResult.php',
@ -48,7 +52,8 @@
'Testable' => 'TUnit/framework/test/Testable.php', 'Testable' => 'TUnit/framework/test/Testable.php',
'TrueConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php', 'TrueConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
'Usage' => 'TUnit/util/cli.php', 'Usage' => 'TUnit/util/cli.php',
'Util' => 'TUnit/util/Util.php' 'Util' => 'TUnit/util/Util.php',
'Verifiable' => 'TUnit/framework/mock/Verifiable.php'
); );
?> ?>