comments, and combined single test results into one file

This commit is contained in:
tmont 2009-06-28 01:01:46 +00:00
parent 10f258f2f9
commit e56fa884ed
10 changed files with 481 additions and 102 deletions

View File

@ -1,41 +1,140 @@
<?php
/**
* CombinedTestResult
*
* @package TUnit
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
/**
* Represents a collection of test results
*
* @package TUnit
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
class CombinedTestResult implements TestResult {
/**
* @var array
*/
protected $testResults;
/**
* Constructor
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @param array $results Array of {@link TestResult}s
*/
public function __construct(array $results = array()) {
$this->testResults = $results;
}
/**
* {@inheritdoc}
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
* @uses getFailedTestResults()
*
* @return bool
*/
public function passed() {
return count($this->getFailedTestResults()) === 0;
}
/**
* {@inheritdoc}
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
* @uses getFailedTestResults()
*
* @return bool
*/
public function failed() {
return count($this->getFailedTestResults()) > 0;
}
/**
* gets the number of tests
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
* @uses getAllTestResults()
*
* @return int
*/
public function count() {
return count($this->getAllTestResults());
}
public function addTestResult(TestResult $result) {
/**
* Adds a test result
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @param TestResult $result
*/
public final function addTestResult(TestResult $result) {
$this->testResults[] = $result;
}
public function getTestResults() {
/**
* Gets the test results
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @return array
*/
public final function getTestResults() {
return $this->testResults;
}
public function getAllTestResults() {
/**
* Flattens out combined results into single test results and
* returns a single-dimensional array of all of them
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
* @uses RecursiveTestIterator
*
* @return array
*/
public final function getAllTestResults() {
$tests = array();
foreach (new RecursiveIteratorIterator(new RecursiveTestIterator($this->testResults)) as $test) {
$tests[] = $test;
}
return $tests;
}
/**
* Gets all passed test results
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
* @uses getAllTestResults()
*
* @return array
*/
public function getPassedTestResults() {
$passedTests = array();
foreach ($this->getAllTestResults() as $testResult) {
@ -47,6 +146,16 @@
return $passedTests;
}
/**
* Gets all failed test results
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
* @uses getAllTestResults()
*
* @return array
*/
public function getFailedTestResults() {
$failedTests = array();
foreach ($this->getAllTestResults() as $testResult) {
@ -58,26 +167,46 @@
return $failedTests;
}
/**
* Gets all ignored test results
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
* @uses getAllTestResults()
*
* @return array
*/
public function getIgnoredTestResults() {
$failedTests = array();
$ignoredTests = array();
foreach ($this->getAllTestResults() as $testResult) {
if ($testResult instanceof IgnoredTestResult) {
$failedTests[] = $testResult;
$ignoredTests[] = $testResult;
}
}
return $failedTests;
return $ignoredTests;
}
/**
* Gets all erred test results
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
* @uses getAllTestResults()
*
* @return array
*/
public function getErredTestResults() {
$failedTests = array();
$erredTests = array();
foreach ($this->getAllTestResults() as $testResult) {
if ($testResult instanceof ErredTestResult) {
$failedTests[] = $testResult;
$erredTests[] = $testResult;
}
}
return $failedTests;
return $erredTests;
}
}

View File

@ -1,15 +0,0 @@
<?php
class ErredTestResult extends SingleTestResult {
public function passed() {
return false;
}
public function failed() {
return true;
}
}
?>

View File

@ -1,15 +1,54 @@
<?php
/**
* TestFailure, FailedTest, ErredTest, IgnoredTest
*
* @package TUnit
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
/**
* Represents a test failure
*
* @package TUnit
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
class TestFailure extends Exception {
/**
* @var Exception|null
*/
protected $innerException;
/**
* Constructor
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @param string $message
* @param Exception $innerException
*/
public function __construct($message = '', Exception $innerException = null) {
parent::__construct($message);
$this->innerException = $innerException;
}
/**
* Gets the stack trace for the test failure
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @return string
*/
public function getStackTrace() {
$trace = ($this->innerException !== null) ? $this->innerException->getTrace() : $this->getTrace();
$count = 1;
@ -48,8 +87,34 @@
}
/**
* A failed test
*
* @package TUnit
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
class FailedTest extends TestFailure {}
/**
* An erred test
*
* @package TUnit
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
class ErredTest extends FailedTest {}
/**
* An ignored test
*
* @package TUnit
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
class IgnoredTest extends TestFailure {}
?>

View File

@ -1,15 +0,0 @@
<?php
class FailedTestResult extends SingleTestResult {
public function passed() {
return false;
}
public function failed() {
return true;
}
}
?>

View File

@ -1,15 +0,0 @@
<?php
class IgnoredTestResult extends SingleTestResult {
public function passed() {
return false;
}
public function failed() {
return false;
}
}
?>

View File

@ -1,15 +0,0 @@
<?php
class PassedTestResult extends SingleTestResult {
public function passed() {
return true;
}
public function failed() {
return false;
}
}
?>

View File

@ -1,27 +0,0 @@
<?php
abstract class SingleTestResult implements TestResult {
protected $test;
protected $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

@ -0,0 +1,241 @@
<?php
/**
* Single test results
*
* @package TUnit
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
/**
* Represents a single test result
*
* @package TUnit
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
abstract class SingleTestResult implements TestResult {
/**
* @var Testable
*/
protected $test;
/**
* @var TestFailure|null
*/
protected $failure;
/**
* Constructor
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @param Testable $test
* @param TestFailure $failure
*/
public function __construct(Testable $test, TestFailure $failure = null) {
$this->test = $test;
$this->failure = $failure;
}
/**
* Gets the test
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @return Testable
*/
public function getTest() {
return $this->test;
}
/**
* Gets the failure, or null if the test did not fail
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @return TestFailure|null
*/
public function getFailure() {
return $this->failure;
}
/**
* Gets the number of tests
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @return int Always returns one
*/
public function count() {
return 1;
}
}
/**
* The test erred
*
* @package TUnit
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
class ErredTestResult extends SingleTestResult {
/**
* {@inheritdoc}
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @return bool
*/
public function passed() {
return false;
}
/**
* {@inheritdoc}
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @return bool
*/
public function failed() {
return true;
}
}
/**
* The test passed
*
* @package TUnit
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
class PassedTestResult extends SingleTestResult {
/**
* {@inheritdoc}
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @return bool
*/
public function passed() {
return true;
}
/**
* {@inheritdoc}
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @return bool
*/
public function failed() {
return false;
}
}
/**
* The test was ignored
*
* @package TUnit
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
class IgnoredTestResult extends SingleTestResult {
/**
* {@inheritdoc}
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @return bool
*/
public function passed() {
return false;
}
/**
* {@inheritdoc}
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @return bool
*/
public function failed() {
return false;
}
}
/**
* The test failed
*
* @package TUnit
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
class FailedTestResult extends SingleTestResult {
/**
* {@inheritdoc}
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @return bool
*/
public function passed() {
return false;
}
/**
* {@inheritdoc}
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*
* @return bool
*/
public function failed() {
return true;
}
}
?>

View File

@ -1,9 +1,40 @@
<?php
/**
* TestResult
*
* @package TUnit
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
/**
* Test result interface
*
* @package TUnit
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
interface TestResult extends Countable {
/**
* Gets whether the test(s) passed
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
public function passed();
/**
* Gets whether the test(s) failed
*
* @author Tommy Montgomery
* @version 1.0
* @since 1.0
*/
public function failed();
}

View File

@ -3,7 +3,7 @@
/**
* Autoload manifest
*
* Autogenerated by manifester.php on 2009-06-27 17:25:10
* Autogenerated by manifester.php on 2009-06-27 18:01:26
*
* @package TUnit
* @version 0.4.0
@ -26,13 +26,13 @@
'EmptyConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
'EqualConstraint' => 'TUnit/framework/constraints/EqualConstraint.php',
'ErredTest' => 'TUnit/framework/result/FailedTest.php',
'ErredTestResult' => 'TUnit/framework/result/ErredTestResult.php',
'ErredTestResult' => 'TUnit/framework/result/SingleTestResults.php',
'FailedTest' => 'TUnit/framework/result/FailedTest.php',
'FailedTestResult' => 'TUnit/framework/result/FailedTestResult.php',
'FailedTestResult' => 'TUnit/framework/result/SingleTestResults.php',
'FalseConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
'IdenticalConstraint' => 'TUnit/framework/constraints/IdenticalConstraint.php',
'IgnoredTest' => 'TUnit/framework/result/FailedTest.php',
'IgnoredTestResult' => 'TUnit/framework/result/IgnoredTestResult.php',
'IgnoredTestResult' => 'TUnit/framework/result/SingleTestResults.php',
'InvalidOptionException' => 'TUnit/framework/exceptions/Exceptions.php',
'InvocationExpectation' => 'TUnit/framework/mock/InvocationExpectation.php',
'InvocationTracker' => 'TUnit/framework/mock/InvocationTracker.php',
@ -44,14 +44,14 @@
'MockRegistry' => 'TUnit/framework/mock/MockRegistry.php',
'NotConstraint' => 'TUnit/framework/constraints/NotConstraint.php',
'NullConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
'PassedTestResult' => 'TUnit/framework/result/PassedTestResult.php',
'PassedTestResult' => 'TUnit/framework/result/SingleTestResults.php',
'PhpFileIterator' => 'TUnit/util/PhpFileIterator.php',
'Product' => 'TUnit/util/Product.php',
'RecursivePhpFileIterator' => 'TUnit/util/PhpFileIterator.php',
'RecursiveTestIterator' => 'TUnit/util/RecursiveTestIterator.php',
'RecursivelyCountable' => 'TUnit/framework/test/Testable.php',
'SimpleConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
'SingleTestResult' => 'TUnit/framework/result/SingleTestResult.php',
'SingleTestResult' => 'TUnit/framework/result/SingleTestResults.php',
'TUnitException' => 'TUnit/framework/exceptions/Exceptions.php',
'TestAccumulator' => 'TUnit/util/TestAccumulator.php',
'TestCase' => 'TUnit/framework/test/TestCase.php',