fixed a bunch of parse errors
This commit is contained in:
parent
65fba62f5d
commit
67a34c7b8f
@ -200,9 +200,8 @@
|
||||
if ($failure instanceof TestFailure) {
|
||||
$this->out("\n");
|
||||
$this->out("----------- FAILURE -----------\n");
|
||||
$this->out($result->getTest()->getName() . "\n\n");
|
||||
$this->out($failure->getMessage());
|
||||
$this->out("\n\nStack trace:\n");
|
||||
$this->out('Test name: ' . $result->getTest()->getName() . "\n");
|
||||
$this->out('Message: ' . $failure->getMessage() . "\n\n");
|
||||
$this->out($failure->getStackTrace());
|
||||
$this->out("\n");
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
abstract class MockInvocation implements Verifiable {
|
||||
class MockInvocation {
|
||||
|
||||
protected $method;
|
||||
protected $args;
|
||||
|
@ -9,8 +9,8 @@
|
||||
|
||||
protected static $registry = array();
|
||||
|
||||
public function __construct($class) {
|
||||
if (!class_exists($class) || !interface_exists($class)) {
|
||||
public function __construct($class, $callParent = true) {
|
||||
if (!class_exists($class) && !interface_exists($class)) {
|
||||
throw new InvalidArgumentException('The class "' . $class . '" does not exist');
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
'default' => array(
|
||||
$this->referenceObject->getConstructor()->getName() => array(
|
||||
'body' => '',
|
||||
'call_parent' => true
|
||||
'call_parent' => (bool)$callParent
|
||||
)
|
||||
),
|
||||
'generic' => array()
|
||||
@ -52,7 +52,7 @@
|
||||
$methodType = 'generic';
|
||||
if ($this->referenceObject->hasMethod($methodName)) {
|
||||
$method = $this->referenceObject->getMethod($methodName);
|
||||
if (!$this->methodIsMockable($method))
|
||||
if (!$this->methodIsMockable($method)) {
|
||||
throw new LogicException('The method "' . $methodName . '" is static, private or final and cannot be mocked');
|
||||
}
|
||||
|
||||
@ -92,9 +92,10 @@
|
||||
$code = $this->generateClassDefinition($name);
|
||||
eval($code);
|
||||
|
||||
self::$registry[$name] = new InvocationTracker();
|
||||
|
||||
$obj = new ReflectionClass($name);
|
||||
$obj = $obj->newInstanceArgs($constructorArgs);
|
||||
self::$registry[$name] = new InvocationTracker();
|
||||
return $obj;
|
||||
}
|
||||
|
||||
@ -103,14 +104,14 @@
|
||||
if ($this->referenceObject->isInterface()) {
|
||||
$code .= 'implements ' . $this->referenceObject->getName() . ', MockObject';
|
||||
} else {
|
||||
$code .= 'extends ' . $this->getReferenceObject->getName() . ' implements MockObject';
|
||||
$code .= 'extends ' . $this->referenceObject->getName() . ' implements MockObject';
|
||||
}
|
||||
|
||||
$code .= " {\n";
|
||||
|
||||
foreach ($this->methods as $type => $methods) {
|
||||
foreach ($methods as $method => $methodData) {
|
||||
$code .= $this->generateMethodDefinition($type, $method, $methodData);
|
||||
$code .= $this->generateMethodDefinition($type, $method, $methodData) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,12 +126,16 @@
|
||||
if ($type === 'default') {
|
||||
$method = $this->referenceObject->getMethod($name);
|
||||
$modifier = ($method->isPublic()) ? 'public' : 'protected';
|
||||
$params = Util::buildParameterList($method);
|
||||
$paramList = Util::getParameterNameList($method);
|
||||
$params = Util::buildParameterDefinition($method);
|
||||
$paramList = Util::buildParameterNameList($method);
|
||||
}
|
||||
|
||||
$varName = '$___args_' . uniqid();
|
||||
|
||||
$code = " $modifier function $name($params) {\n";
|
||||
$code .= " MockObject::registerInvocation(get_class($this), __FUNCTION__, func_get_args());\n";
|
||||
$code .= " $varName = func_get_args();\n";
|
||||
$code .= " MockObjectCreator::registerInvocation(get_class(\$this), __FUNCTION__, $varName);\n";
|
||||
$code .= " unset($varName);\n";
|
||||
|
||||
if ($methodData['call_parent']) {
|
||||
$code .= " parent::$name($paramList);\n";
|
||||
@ -139,7 +144,7 @@
|
||||
$code .= "\t\t" . str_replace("\n", "\n\t\t", $methodData['body']) . "\n";
|
||||
}
|
||||
|
||||
$code .= ' }';
|
||||
$code .= " }";
|
||||
return $code;
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,20 @@
|
||||
|
||||
class TestFailure extends Exception {
|
||||
|
||||
protected $innerException;
|
||||
|
||||
public function __construct($message = '', Exception $innerException = null) {
|
||||
parent::__construct($message);
|
||||
|
||||
$this->innerException = $innerException;
|
||||
}
|
||||
|
||||
public function getStackTrace() {
|
||||
$trace = $this->getTrace();
|
||||
$trace = ($this->innerException !== null) ? $this->innerException->getTrace() : $this->getTrace();
|
||||
$count = 1;
|
||||
$stackTrace = array();
|
||||
foreach (array_slice($trace, 2) as $i => $frame) {
|
||||
//array_slice($trace, 2)
|
||||
foreach ($trace as $i => $frame) {
|
||||
$line = '[' . ($i + 1) . '] ';
|
||||
if (isset($frame['file'], $frame['line'])) {
|
||||
if ($frame['file'] === dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'TestMethod.php') {
|
||||
@ -23,7 +32,7 @@
|
||||
}
|
||||
|
||||
if (isset($frame['args']) && !empty($frame['args'])) {
|
||||
$line .= implode(', ', array_map('TestFailure::transformArgs', $frame['args']));
|
||||
$line .= implode(', ', array_map('Util::export', $frame['args']));
|
||||
}
|
||||
|
||||
$line .= ')';
|
||||
@ -35,10 +44,6 @@
|
||||
return implode("\n", $stackTrace);
|
||||
}
|
||||
|
||||
protected static function transformArgs($value) {
|
||||
return Util::export($value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class FailedTest extends TestFailure {}
|
||||
|
@ -50,6 +50,16 @@
|
||||
return $methods;
|
||||
}
|
||||
|
||||
protected function createMockObject($className, array $methods = array(), array $args = array(), $name = '', $callParent = true) {
|
||||
$creator = new MockObjectCreator($className, $callParent);
|
||||
|
||||
foreach ($methods as $method) {
|
||||
$creator->addMethod($method);
|
||||
}
|
||||
|
||||
return $creator->generate($args, $name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -35,6 +35,8 @@
|
||||
foreach ($listeners as $listener) {
|
||||
$listener->onTestMethodErred($this);
|
||||
}
|
||||
|
||||
$failure = new ErredTest($e->getMessage(), $e);
|
||||
}
|
||||
|
||||
$result = $this->createTestResult($failure);
|
||||
@ -47,13 +49,13 @@
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function createTestResult(TestFailure $failure = null) {
|
||||
protected function createTestResult(Exception $failure = null) {
|
||||
if ($failure === null) {
|
||||
return new PassedTestResult($this);
|
||||
} else if ($failure instanceof FailedTest) {
|
||||
return new FailedTestResult($this, $failure);
|
||||
} else if ($failure instanceof ErredTest) {
|
||||
return new ErredTestResult($this, $failure);
|
||||
} else if ($failure instanceof FailedTest) {
|
||||
return new FailedTestResult($this, $failure);
|
||||
} else if ($failure instanceof IgnoredTest) {
|
||||
return new IgnoredTestResult($this, $failure);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@
|
||||
return rtrim($paramList, ', ');
|
||||
}
|
||||
|
||||
private static repairParameterName($name, $position) {
|
||||
private static function repairParameterName($name, $position) {
|
||||
if (empty($name)) {
|
||||
$name = 'param' . $position;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user