result publishing: mostly done

This commit is contained in:
tmont 2009-06-13 23:47:25 +00:00
parent 035a5da679
commit 98b11c6870
12 changed files with 141 additions and 49 deletions

View File

@ -49,10 +49,10 @@
public function afterTestSuite(TestSuite $suite) {
switch ($this->verbosity) {
case self::VERBOSITY_HIGH:
case self::VERBOSITY_MEDIUM:
$this->out("\n");
break;
case self::VERBOSITY_LOW:
case self::VERBOSITY_MEDIUM:
default:
break;
}
@ -195,6 +195,19 @@
}
}
public function publishTestResult(TestResult $result) {
$failure = $result->getFailure();
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($failure->getStackTrace());
$this->out("\n");
}
}
}
?>

View File

@ -24,11 +24,18 @@
$this->testResults[] = $result;
}
public function getAllTestResults() {
//use a recursive iterator here...
public function getTestResults() {
return $this->testResults;
}
public function getAllTestResults() {
$tests = array();
foreach (new RecursiveIteratorIterator(new RecursiveTestIterator($this->testResults)) as $test) {
$tests[] = $test;
}
return $tests;
}
public function getPassedTestResults() {
//use a recursive iterator here...
$passedTests = array();

View File

@ -1,8 +1,50 @@
<?php
class TestFailure extends Exception {}
class ErredTest extends FailedTest {}
class IgnoredTest extends FailedTest {}
class TestFailure extends Exception {
public function getStackTrace() {
$trace = $this->getTrace();
$count = 1;
$stackTrace = array();
foreach (array_slice($trace, 2) 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') {
break;
}
$line .= $frame['file'] . ' (' . $frame['line'] . ') ';
} else {
$line .= '<internal function> ';
}
if (isset($frame['class']) || isset($frame['function'])) {
if (isset($frame['class'], $frame['type'], $frame['function']) && !empty($frame['type'])) {
$line .= $frame['class'] . $frame['type'] . $frame['function'] . '(';
} else {
$line .= $frame['function'] . '(';
}
if (isset($frame['args']) && !empty($frame['args'])) {
$line .= implode(', ', array_map('TestFailure::transformArgs', $frame['args']));
}
$line .= ')';
}
$stackTrace[] = $line;
}
return implode("\n", $stackTrace);
}
protected static function transformArgs($value) {
return Util::export($value);
}
}
class FailedTest extends TestFailure {}
class ErredTest extends FailedTest {}
class IgnoredTest extends TestFailure {}
?>

View File

@ -1,12 +1,6 @@
<?php
class PassedTestResult implements TestResult {
protected $test;
public function __construct(Testable $test) {
$this->test = $test;
}
class PassedTestResult extends SingleTestResult {
public function passed() {
return true;
@ -16,10 +10,6 @@
return false;
}
public function count() {
return 1;
}
}
?>

View File

@ -5,11 +5,19 @@
protected $test;
protected $failure;
public function __construct(Testable $test, TestFailure $failure) {
public function __construct(Testable $test, TestFailure $failure = null) {
$this->test = $test;
$this->failure = $failure;
}
public function getTest() {
return $this->test;
}
public function getFailure() {
return $this->failure;
}
public function count() {
return 1;
}

View File

@ -8,6 +8,10 @@
$this->name = $name;
}
public function getName() {
return $this->name;
}
public function setUp() {
}

View File

@ -10,6 +10,10 @@
$this->method = $method;
}
public function getName() {
return $this->method->getDeclaringClass()->getName() . '::' . $this->method->getName();
}
public function run(array $listeners) {
foreach ($listeners as $listener) {
$listener->beforeTestMethod($this);

View File

@ -10,6 +10,10 @@
$this->tests = $tests;
}
public function getName() {
return $this->name;
}
protected function setUp() {
}

View File

@ -4,6 +4,8 @@
public function run(array $listeners);
public function getName();
}
?>

View File

@ -3,7 +3,7 @@
/**
* Autoload manifest
*
* Autogenerated by manifester.php on 2009-06-13 15:40:20
* Autogenerated by manifester.php on 2009-06-13 15:51:52
*
* @package TUnit
* @version 0.1.0
@ -11,33 +11,34 @@
*/
return array(
'Assert' => 'TUnit/framework/Assert.php',
'Autoloader' => 'TUnit/util/Autoloader.php',
'Cli' => 'TUnit/util/cli.php',
'CliSwitch' => 'TUnit/util/cli.php',
'CliSwitchCollection' => 'TUnit/util/cli.php',
'CombinedTestResult' => 'TUnit/framework/result/CombinedTestResult.php',
'ConsoleListener' => 'TUnit/framework/listeners/ConsoleListener.php',
'Constraint' => 'TUnit/framework/constraints/Constraint.php',
'EqualsConstraint' => 'TUnit/framework/constraints/EqualsConstraint.php',
'ErredTest' => 'TUnit/framework/result/FailedTest.php',
'ErredTestResult' => 'TUnit/framework/result/ErredTestResult.php',
'FailedTest' => 'TUnit/framework/result/FailedTest.php',
'FailedTestResult' => 'TUnit/framework/result/FailedTestResult.php',
'IgnoredTest' => 'TUnit/framework/result/FailedTest.php',
'IgnoredTestResult' => 'TUnit/framework/result/IgnoredTestResult.php',
'PassedTestResult' => 'TUnit/framework/result/PassedTestResult.php',
'SingleTestResult' => 'TUnit/framework/result/SingleTestResult.php',
'TestCase' => 'TUnit/framework/test/TestCase.php',
'TestFailure' => 'TUnit/framework/result/FailedTest.php',
'TestListener' => 'TUnit/framework/listeners/TestListener.php',
'TestMethod' => 'TUnit/framework/test/TestMethod.php',
'TestResult' => 'TUnit/framework/result/TestResult.php',
'TestRunner' => 'TUnit/framework/TestRunner.php',
'TestSuite' => 'TUnit/framework/test/TestSuite.php',
'Testable' => 'TUnit/framework/test/Testable.php',
'Usage' => 'TUnit/util/cli.php',
'Util' => 'TUnit/util/Util.php'
'Assert' => 'TUnit/framework/Assert.php',
'Autoloader' => 'TUnit/util/Autoloader.php',
'Cli' => 'TUnit/util/cli.php',
'CliSwitch' => 'TUnit/util/cli.php',
'CliSwitchCollection' => 'TUnit/util/cli.php',
'CombinedTestResult' => 'TUnit/framework/result/CombinedTestResult.php',
'ConsoleListener' => 'TUnit/framework/listeners/ConsoleListener.php',
'Constraint' => 'TUnit/framework/constraints/Constraint.php',
'EqualsConstraint' => 'TUnit/framework/constraints/EqualsConstraint.php',
'ErredTest' => 'TUnit/framework/result/FailedTest.php',
'ErredTestResult' => 'TUnit/framework/result/ErredTestResult.php',
'FailedTest' => 'TUnit/framework/result/FailedTest.php',
'FailedTestResult' => 'TUnit/framework/result/FailedTestResult.php',
'IgnoredTest' => 'TUnit/framework/result/FailedTest.php',
'IgnoredTestResult' => 'TUnit/framework/result/IgnoredTestResult.php',
'PassedTestResult' => 'TUnit/framework/result/PassedTestResult.php',
'RecursiveTestIterator' => 'TUnit/util/RecursiveTestIterator.php',
'SingleTestResult' => 'TUnit/framework/result/SingleTestResult.php',
'TestCase' => 'TUnit/framework/test/TestCase.php',
'TestFailure' => 'TUnit/framework/result/FailedTest.php',
'TestListener' => 'TUnit/framework/listeners/TestListener.php',
'TestMethod' => 'TUnit/framework/test/TestMethod.php',
'TestResult' => 'TUnit/framework/result/TestResult.php',
'TestRunner' => 'TUnit/framework/TestRunner.php',
'TestSuite' => 'TUnit/framework/test/TestSuite.php',
'Testable' => 'TUnit/framework/test/Testable.php',
'Usage' => 'TUnit/util/cli.php',
'Util' => 'TUnit/util/Util.php'
);
?>

View File

@ -0,0 +1,15 @@
<?php
class RecursiveTestIterator extends ArrayIterator implements RecursiveIterator {
public function getChildren() {
return new self($this->current()->getTestResults());
}
public function hasChildren() {
return $this->current() instanceof CombinedTestResult;
}
}
?>

View File

@ -9,11 +9,11 @@
case 'object':
return get_class($var);
case 'string':
if (strlen($var) > 47) {
return substr($var, 0, 20) . '...' . substr($var, floor(strlen($var) / 2) - 3, 7) . '...' . substr($var, -20);
if (strlen($var) > 20) {
return '"' . substr($var, 0, 10) . '...' . substr($var, -10) . '"';
}
return $var;
return '"' . $var . '"';
case 'double':
case 'null':
case 'boolean':
@ -21,6 +21,8 @@
return var_export($var, true);
case 'resource':
return 'resource of type ' . get_resource_type($var);
case 'array':
return 'array(' . count($var) . ')';
}
}