* don't explode if a @test annotated method is not public or has an invalid method signature
* added framework error/warning publishing
This commit is contained in:
parent
16d163254c
commit
9c095eac8c
@ -284,6 +284,29 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Publishes framework errors
|
||||
*
|
||||
* @author Tommy Montgomery
|
||||
* @version 1.0
|
||||
* @since 1.0
|
||||
* @uses ErrorStack::getWarnings()
|
||||
* @uses ErrorStack::getErrors()
|
||||
* @uses err()
|
||||
* @uses warn()
|
||||
*/
|
||||
public function publishErrors() {
|
||||
$warnings = ErrorStack::getWarnings();
|
||||
foreach ($warnings as $message) {
|
||||
$this->warn($message);
|
||||
}
|
||||
|
||||
$errors = ErrorStack::getErrors();
|
||||
foreach ($errors as $message) {
|
||||
$this->err($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before runTests()
|
||||
*
|
||||
@ -303,6 +326,7 @@
|
||||
* @since 1.0
|
||||
* @uses TestListener::beforeTestRunner()
|
||||
* @uses publishResults()
|
||||
* @uses publishErrors()
|
||||
* @uses TestListener::afterTestRunner()
|
||||
*/
|
||||
public final function run() {
|
||||
@ -317,6 +341,7 @@
|
||||
$this->endTime = microtime(true);
|
||||
|
||||
$this->publishResults($results);
|
||||
$this->publishErrors();
|
||||
|
||||
foreach ($this->listeners as $listener) {
|
||||
$listener->afterTestRunner($this);
|
||||
|
51
src/Testify/framework/ErrorStack.php
Normal file
51
src/Testify/framework/ErrorStack.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
final class ErrorStack {
|
||||
|
||||
private static $errorStack = array();
|
||||
private static $warningStack = array();
|
||||
|
||||
private function __construct() {}
|
||||
|
||||
private static function addToStack($message, $type = 'error') {
|
||||
if ($message instanceof Exception) {
|
||||
$message = $e->getMessage() . "\n" . $e->getTraceAsString();
|
||||
} else if (!is_string($message)) {
|
||||
throw new InvalidArgumentException('1st argument must be a string or an instance of Exception');
|
||||
}
|
||||
|
||||
if ($type === 'warning') {
|
||||
self::$warningStack[] = $message;
|
||||
} else {
|
||||
self::$errorStack[] = $message;
|
||||
}
|
||||
}
|
||||
|
||||
public static function addError($message) {
|
||||
self::addToStack($message, 'error');
|
||||
}
|
||||
|
||||
public static function addWarning($message) {
|
||||
self::addToStack($message, 'warning');
|
||||
}
|
||||
|
||||
public static function getErrors() {
|
||||
return self::$errorStack;
|
||||
}
|
||||
|
||||
public static function getWarnings() {
|
||||
return self::$warningStack;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
return array_merge(self::$errorStack, self::$warningStack);
|
||||
}
|
||||
|
||||
public static function clear() {
|
||||
self::$errorStack = array();
|
||||
self::$warningStack = array();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -425,7 +425,7 @@
|
||||
* @param mixed $message
|
||||
*/
|
||||
public function onFrameworkError($message) {
|
||||
$this->err('ERROR: ' . $message);
|
||||
$this->err('ERROR: ' . $message . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -439,7 +439,7 @@
|
||||
*/
|
||||
public function onFrameworkWarning($message) {
|
||||
if ($this->verbosity > self::VERBOSITY_LOW) {
|
||||
$this->out('WARNING: ' . $message);
|
||||
$this->out('WARNING: ' . $message . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,17 @@
|
||||
$method->getDeclaringClass()->getName() !== __CLASS__ &&
|
||||
preg_match('/^[\/\*\s]*@test\s*(?:\*\/)?$/m', $method->getDocComment())
|
||||
) {
|
||||
$methods[$method->getName()] = new TestMethod(Util::getClosure($this, $method->getName()), get_class($this) . '::' . $method->getName(), $this->getAutoVerify());
|
||||
$name = get_class($this) . '::' . $method->getName();
|
||||
if (!$method->isPublic()) {
|
||||
ErrorStack::addWarning('The test ' . $name . ' is not a public method');
|
||||
continue;
|
||||
}
|
||||
if (count($method->getParameters()) > 0) {
|
||||
ErrorStack::addWarning('The test ' . $name . ' has an invalid method signature');
|
||||
continue;
|
||||
}
|
||||
|
||||
$methods[$method->getName()] = new TestMethod(Util::getClosure($this, $method->getName()), $name, $this->getAutoVerify());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
/**
|
||||
* Autoload manifest
|
||||
*
|
||||
* Autogenerated by manifester.php on 2009-07-08 01:27:37
|
||||
* Autogenerated by manifester.php on 2009-07-08 02:00:33
|
||||
*
|
||||
* @package Testify
|
||||
* @version 0.7.0
|
||||
@ -33,6 +33,7 @@
|
||||
'EqualConstraint' => 'Testify/framework/constraints/EqualConstraint.php',
|
||||
'ErredTest' => 'Testify/framework/result/FailedTest.php',
|
||||
'ErredTestResult' => 'Testify/framework/result/SingleTestResults.php',
|
||||
'ErrorStack' => 'Testify/framework/ErrorStack.php',
|
||||
'FailedTest' => 'Testify/framework/result/FailedTest.php',
|
||||
'FailedTestResult' => 'Testify/framework/result/SingleTestResults.php',
|
||||
'FalseConstraint' => 'Testify/framework/constraints/SimpleConstraints.php',
|
||||
|
Loading…
Reference in New Issue
Block a user