2008-08-09 08:18:32 +02:00
|
|
|
<?php
|
2012-08-09 11:51:17 +02:00
|
|
|
if(!class_exists('PHPUnit_Framework_TestResult', false)) require_once 'PHPUnit/Framework/TestResult.php';
|
|
|
|
if(!class_exists('PHPUnit_Framework_TestListener', false)) require_once 'PHPUnit/Framework/TestListener.php';
|
2008-08-09 08:18:32 +02:00
|
|
|
|
|
|
|
/**#@+
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Failure test status constant
|
|
|
|
*/
|
|
|
|
define('TEST_FAILURE', -1);
|
|
|
|
/**
|
|
|
|
* Error test status constant
|
|
|
|
*/
|
|
|
|
define('TEST_ERROR', 0);
|
|
|
|
/**
|
|
|
|
* Success test status constant
|
|
|
|
*/
|
|
|
|
define('TEST_SUCCESS', 1);
|
|
|
|
/**
|
|
|
|
* Incomplete test status constant
|
|
|
|
*/
|
|
|
|
define('TEST_INCOMPLETE', 2);
|
|
|
|
/**#@-*/
|
|
|
|
|
2010-04-23 02:11:41 +02:00
|
|
|
/**
|
|
|
|
* Gathers details about PHPUnit2 test suites as they
|
|
|
|
* are been executed. This does not actually format any output
|
|
|
|
* but simply gathers extended information about the overall
|
|
|
|
* results of all suites & their tests for use elsewhere.
|
|
|
|
*
|
|
|
|
* Changelog:
|
|
|
|
* 0.6 First created [David Spurr]
|
|
|
|
* 0.7 Added fix to getTestException provided [Glen Ogilvie]
|
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2010-04-23 02:11:41 +02:00
|
|
|
* @subpackage testing
|
|
|
|
*
|
|
|
|
* @version 0.7 2006-03-12
|
|
|
|
* @author David Spurr
|
|
|
|
*/
|
2008-08-09 08:18:32 +02:00
|
|
|
class SapphireTestReporter implements PHPUnit_Framework_TestListener {
|
|
|
|
/**
|
|
|
|
* Holds array of suites and total number of tests run
|
|
|
|
* @var array
|
|
|
|
*/
|
2008-08-13 03:47:05 +02:00
|
|
|
protected $suiteResults;
|
2008-08-09 08:18:32 +02:00
|
|
|
/**
|
|
|
|
* Holds data of current suite that is been run
|
|
|
|
* @var array
|
|
|
|
*/
|
2008-08-13 03:47:05 +02:00
|
|
|
protected $currentSuite;
|
2008-08-09 08:18:32 +02:00
|
|
|
/**
|
|
|
|
* Holds data of current test that is been run
|
|
|
|
* @var array
|
|
|
|
*/
|
2008-08-13 03:47:05 +02:00
|
|
|
protected $currentTest;
|
2008-08-09 08:18:32 +02:00
|
|
|
/**
|
|
|
|
* Whether PEAR Benchmark_Timer is available for timing
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2008-08-13 03:47:05 +02:00
|
|
|
protected $hasTimer;
|
2008-08-09 08:18:32 +02:00
|
|
|
/**
|
|
|
|
* Holds the PEAR Benchmark_Timer object
|
|
|
|
* @var obj Benchmark_Timer
|
|
|
|
*/
|
2008-08-13 03:47:05 +02:00
|
|
|
protected $timer;
|
2008-08-09 08:18:32 +02:00
|
|
|
|
2008-10-17 04:28:55 +02:00
|
|
|
protected $startTestTime;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An array of all the test speeds
|
|
|
|
*/
|
|
|
|
protected $testSpeeds = array();
|
|
|
|
|
2008-08-09 08:18:32 +02:00
|
|
|
/**
|
|
|
|
* Constructor, checks to see availability of PEAR Benchmark_Timer and
|
|
|
|
* sets up basic properties
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
@include_once 'Benchmark/Timer.php';
|
2008-08-09 08:18:32 +02:00
|
|
|
if(class_exists('Benchmark_Timer')) {
|
|
|
|
$this->timer = new Benchmark_Timer();
|
|
|
|
$this->hasTimer = true;
|
|
|
|
} else {
|
|
|
|
$this->hasTimer = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->suiteResults = array(
|
|
|
|
'suites' => array(), // array of suites run
|
|
|
|
'hasTimer' => $this->hasTimer, // availability of PEAR Benchmark_Timer
|
|
|
|
'totalTests' => 0 // total number of tests run
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the suite results
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return array Suite results
|
|
|
|
*/
|
|
|
|
public function getSuiteResults() {
|
|
|
|
return $this->suiteResults;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up the container for result details of the current test suite when
|
|
|
|
* each suite is first run
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param obj PHPUnit2_Framework_TestSuite, the suite that is been run
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function startTestSuite( PHPUnit_Framework_TestSuite $suite) {
|
|
|
|
if(strlen($suite->getName())) {
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
$this->endCurrentTestSuite();
|
2008-08-09 08:18:32 +02:00
|
|
|
$this->currentSuite = array(
|
|
|
|
'suite' => $suite, // the test suite
|
|
|
|
'tests' => array(), // the tests in the suite
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
'errors' => 0, // number of tests with errors (including setup errors)
|
2008-08-09 08:18:32 +02:00
|
|
|
'failures' => 0, // number of tests which failed
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
'incomplete' => 0, // number of tests that were not completed correctly
|
|
|
|
'error' => null); // Any error encountered during setup of the test suite
|
2008-08-09 08:18:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up the container for result details of the current test when each
|
|
|
|
* test is first run
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param obj PHPUnit_Framework_Test, the test that is being run
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function startTest(PHPUnit_Framework_Test $test) {
|
2008-10-17 04:28:55 +02:00
|
|
|
$this->startTestTime = microtime(true);
|
|
|
|
|
2008-08-09 08:18:32 +02:00
|
|
|
if($test instanceof PHPUnit_Framework_TestCase) {
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
$this->endCurrentTest();
|
2008-08-09 08:18:32 +02:00
|
|
|
$this->currentTest = array(
|
2012-09-26 23:34:00 +02:00
|
|
|
// the name of the test (without the suite name)
|
|
|
|
'name' => preg_replace('(\(.*\))', '', $test->toString()),
|
|
|
|
// execution time of the test
|
|
|
|
'timeElapsed' => 0,
|
|
|
|
// status of the test execution
|
|
|
|
'status' => TEST_SUCCESS,
|
|
|
|
// user message of test result
|
|
|
|
'message' => '',
|
|
|
|
// original caught exception thrown by test upon failure/error
|
|
|
|
'exception' => NULL,
|
|
|
|
// Stacktrace used for exception handling
|
|
|
|
'trace' => NULL,
|
|
|
|
// a unique ID for this test (used for identification purposes in results)
|
|
|
|
'uid' => md5(microtime())
|
2008-08-09 08:18:32 +02:00
|
|
|
);
|
|
|
|
if($this->hasTimer) $this->timer->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
/**
|
|
|
|
* Logs the specified status to the current test, or if no test is currently
|
|
|
|
* run, to the test suite.
|
|
|
|
* @param integer $status Status code
|
|
|
|
* @param string $message Message to log
|
|
|
|
* @param string $exception Exception body related to this message
|
|
|
|
* @param array $trace Stacktrace
|
|
|
|
*/
|
|
|
|
protected function addStatus($status, $message, $exception, $trace) {
|
|
|
|
// Build status body to be saved
|
|
|
|
$status = array(
|
|
|
|
'status' => $status,
|
|
|
|
'message' => $message,
|
|
|
|
'exception' => $exception,
|
|
|
|
'trace' => $trace
|
|
|
|
);
|
|
|
|
|
|
|
|
// Log either to current test or suite record
|
|
|
|
if($this->currentTest) {
|
|
|
|
$this->currentTest = array_merge($this->currentTest, $status);
|
|
|
|
} else {
|
|
|
|
$this->currentSuite['error'] = $status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-09 08:18:32 +02:00
|
|
|
/**
|
|
|
|
* Adds the failure detail to the current test and increases the failure
|
|
|
|
* count for the current suite
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param obj PHPUnit_Framework_Test, current test that is being run
|
|
|
|
* @param obj PHPUnit_Framework_AssertationFailedError, PHPUnit error
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
|
|
|
|
$this->currentSuite['failures']++;
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
$this->addStatus(TEST_FAILURE, $e->toString(), $this->getTestException($test, $e), $e->getTrace());
|
2008-08-09 08:18:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the error detail to the current test and increases the error
|
|
|
|
* count for the current suite
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param obj PHPUnit_Framework_Test, current test that is being run
|
|
|
|
* @param obj PHPUnit_Framework_AssertationFailedError, PHPUnit error
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
|
|
|
$this->currentSuite['errors']++;
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
$this->addStatus(TEST_ERROR, $e->getMessage(), $this->getTestException($test, $e), $e->getTrace());
|
2008-08-09 08:18:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the test incomplete detail to the current test and increases the incomplete
|
|
|
|
* count for the current suite
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param obj PHPUnit_Framework_Test, current test that is being run
|
|
|
|
* @param obj PHPUnit_Framework_AssertationFailedError, PHPUnit error
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
|
|
|
$this->currentSuite['incomplete']++;
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
$this->addStatus(TEST_INCOMPLETE, $e->toString(), $this->getTestException($test, $e), $e->getTrace());
|
2008-08-09 08:18:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Not used
|
|
|
|
*
|
|
|
|
* @param PHPUnit_Framework_Test $test
|
|
|
|
* @param unknown_type $time
|
|
|
|
*/
|
|
|
|
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
|
|
|
// not implemented
|
|
|
|
}
|
|
|
|
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleanly end the current test
|
|
|
|
*/
|
|
|
|
protected function endCurrentTest() {
|
|
|
|
if(!$this->currentTest) return;
|
|
|
|
|
|
|
|
// Time the current test
|
|
|
|
$testDuration = microtime(true) - $this->startTestTime;
|
|
|
|
$this->testSpeeds[$this->currentSuite['suite']->getName() . '.' . $this->currentTest['name']] = $testDuration;
|
|
|
|
if($this->hasTimer) {
|
|
|
|
$this->timer->stop();
|
|
|
|
$this->currentTest['timeElapsed'] = $this->timer->timeElapsed();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save and reset current state
|
|
|
|
array_push($this->currentSuite['tests'], $this->currentTest);
|
|
|
|
$this->currentTest = null;
|
|
|
|
}
|
|
|
|
|
2008-08-09 08:18:32 +02:00
|
|
|
/**
|
|
|
|
* Upon completion of a test, records the execution time (if available) and adds the test to
|
|
|
|
* the tests performed in the current suite.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param obj PHPUnit_Framework_Test, current test that is being run
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function endTest( PHPUnit_Framework_Test $test, $time) {
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
$this->endCurrentTest();
|
2011-12-17 04:31:30 +01:00
|
|
|
if(method_exists($test, 'getActualOutput')) {
|
|
|
|
$output = $test->getActualOutput();
|
|
|
|
if($output) echo "\nOutput:\n$output";
|
|
|
|
}
|
2008-08-09 08:18:32 +02:00
|
|
|
}
|
|
|
|
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
/**
|
|
|
|
* Cleanly end the current test suite
|
|
|
|
*/
|
|
|
|
protected function endCurrentTestSuite() {
|
|
|
|
if(!$this->currentSuite) return;
|
|
|
|
|
|
|
|
// Ensure any current test is ended along with the current suite
|
|
|
|
$this->endCurrentTest();
|
|
|
|
|
|
|
|
// Save and reset current state
|
|
|
|
array_push($this->suiteResults['suites'], $this->currentSuite);
|
|
|
|
$this->currentSuite = null;
|
|
|
|
}
|
|
|
|
|
2008-08-09 08:18:32 +02:00
|
|
|
/**
|
|
|
|
* Upon completion of a test suite adds the suite to the suties performed
|
|
|
|
*
|
2010-10-13 05:53:12 +02:00
|
|
|
* @access public
|
2008-08-09 08:18:32 +02:00
|
|
|
* @param obj PHPUnit_Framework_TestSuite, current suite that is being run
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function endTestSuite( PHPUnit_Framework_TestSuite $suite) {
|
|
|
|
if(strlen($suite->getName())) {
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
$this->endCurrentTestSuite();
|
2008-08-09 08:18:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trys to get the original exception thrown by the test on failure/error
|
|
|
|
* to enable us to give a bit more detail about the failure/error
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
* @param obj PHPUnit_Framework_Test, current test that is being run
|
|
|
|
* @param obj PHPUnit_Framework_AssertationFailedError, PHPUnit error
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getTestException(PHPUnit_Framework_Test $test, Exception $e) {
|
|
|
|
// get the name of the testFile from the test
|
2012-02-27 22:14:02 +01:00
|
|
|
$testName = preg_replace('/(.*)\((.*[^)])\)/', '\\2', $test->toString());
|
2008-08-09 08:18:32 +02:00
|
|
|
$trace = $e->getTrace();
|
|
|
|
// loop through the exception trace to find the original exception
|
|
|
|
for($i = 0; $i < count($trace); $i++) {
|
|
|
|
|
|
|
|
if(array_key_exists('file', $trace[$i])) {
|
|
|
|
if(stristr($trace[$i]['file'], $testName.'.php') != false) return $trace[$i];
|
|
|
|
}
|
|
|
|
if(array_key_exists('file:protected', $trace[$i])) {
|
|
|
|
if(stristr($trace[$i]['file:protected'], $testName.'.php') != false) return $trace[$i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
/**
|
|
|
|
* Writes a status message to the output stream in a user readable HTML format
|
|
|
|
* @param string $name Name of the object that generated the error
|
|
|
|
* @param string $message Message of the error
|
|
|
|
* @param array $trace Stacktrace
|
|
|
|
*/
|
|
|
|
protected function writeResultError($name, $message, $trace) {
|
|
|
|
echo "<div class=\"failure\"><h2 class=\"test-case\">⊗ ". $this->testNameToPhrase($name) ."</h2>";
|
|
|
|
echo "<pre>".htmlentities($message, ENT_COMPAT, 'UTF-8')."</pre>";
|
|
|
|
echo SS_Backtrace::get_rendered_backtrace($trace);
|
|
|
|
echo "</div>";
|
|
|
|
}
|
|
|
|
|
2008-08-09 08:18:32 +02:00
|
|
|
/**
|
|
|
|
* Display error bar if it exists
|
|
|
|
*/
|
2012-04-14 13:11:54 +02:00
|
|
|
public function writeResults() {
|
2008-08-09 08:18:32 +02:00
|
|
|
$passCount = 0;
|
|
|
|
$failCount = 0;
|
|
|
|
$testCount = 0;
|
2012-04-14 13:11:54 +02:00
|
|
|
$incompleteCount = 0;
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
$errorCount = 0; // Includes both suite and test level errors
|
|
|
|
|
|
|
|
// Ensure that the current suite is cleanly ended.
|
|
|
|
// A suite may not end correctly if there was an error during setUp
|
|
|
|
$this->endCurrentTestSuite();
|
2008-08-09 08:18:32 +02:00
|
|
|
|
|
|
|
foreach($this->suiteResults['suites'] as $suite) {
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
|
|
|
|
// Report suite error. In the case of fatal non-success messages
|
|
|
|
// These should be reported as errors. Failure/Success relate only
|
|
|
|
// to individual tests directly
|
|
|
|
if($suite['error']) {
|
|
|
|
$errorCount++;
|
|
|
|
$this->writeResultError(
|
|
|
|
$suite['suite']->getName(),
|
|
|
|
$suite['error']['message'],
|
|
|
|
$suite['error']['trace']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run through all tests in this suite
|
2008-08-09 08:18:32 +02:00
|
|
|
foreach($suite['tests'] as $test) {
|
|
|
|
$testCount++;
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
switch($test['status']) {
|
|
|
|
case TEST_ERROR: $errorCount++; break;
|
|
|
|
case TEST_INCOMPLETE: $incompleteCount++; break;
|
|
|
|
case TEST_SUCCESS: $passCount++; break;
|
|
|
|
case TEST_FAILURE: $failCount++; break;
|
2012-04-14 13:11:54 +02:00
|
|
|
}
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
|
|
|
|
// Report test error
|
|
|
|
if ($test['status'] != TEST_SUCCESS) {
|
|
|
|
$this->writeResultError(
|
|
|
|
$test['name'],
|
|
|
|
$test['message'],
|
|
|
|
$test['trace']
|
|
|
|
);
|
2008-08-09 08:18:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
FIXED: Issue with test reporting not correctly presenting errors that prevent test execution.
In the case of errors arising during setUp or setUpOnce a unit test will fail to run any individual tests. However, this situation was incorrectly being reported as a test pass (as no tests were run, thus no tests had errors). E.g. the output of a test run that raised an error during setUp would be "0 tests run: 0 passes, 0 failures, and 0 incomplete" with a green background.
To rectify this the following fixes were made:
- Non-cleanly ended tests and test suites are now automatically ended at the end of the test run, as well as at the beginning of subsequent test/suites. This should make catching of errors a lot more robust.
- Errors raised during setup are now no longer lost to the mist of time. The test suite itself will record any error status which was generated outside the scope of any individual tests.
- An additional "errors" count is added to the output at the end of test running. For example, in the case where setup failed and no tests could be run the error would be written to the browser (along with stacktrace) with a message similar to "0 tests run: 0 passes, 0 failures, and 0 incomplete with 1 errors". The intent of this is to separate the concepts of failed/succeeded/incomplete tests from any errors which may have arisen. I.e. no tests "failed" due to the error, but the test run itself is highlighted as an error (red background on the output).
This problem has been a severe cause of issue when testing code that interacts with the database, as any database error during setup would refuse to be shown.
2012-09-19 02:25:58 +02:00
|
|
|
$result = ($failCount || $errorCount) ? 'fail' : 'pass';
|
2010-12-11 06:43:08 +01:00
|
|
|
echo "<div class=\"status $result\">";
|
2012-09-26 23:34:00 +02:00
|
|
|
echo "<h2><span>$testCount</span> tests run: <span>$passCount</span> passes, <span>$failCount</span> failures,"
|
|
|
|
. " and <span>$incompleteCount</span> incomplete with <span>$errorCount</span> errors</h2>";
|
2008-08-09 08:18:32 +02:00
|
|
|
echo "</div>";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-08-13 03:47:05 +02:00
|
|
|
protected function testNameToPhrase($name) {
|
2008-08-09 08:18:32 +02:00
|
|
|
return ucfirst(preg_replace("/([a-z])([A-Z])/", "$1 $2", $name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|