diff --git a/dev/CliDebugView.php b/dev/CliDebugView.php index 301ae220d..f22895d8a 100644 --- a/dev/CliDebugView.php +++ b/dev/CliDebugView.php @@ -51,6 +51,19 @@ class CliDebugView extends DebugView { function writeTrace() { Debug::backtrace(); } + + /** + * Render the information header for the view + * + * @param string $title + * @param string $title + */ + public function writeInfo($title, $subtitle, $description=false) { + echo wordwrap(strtoupper($title),100) . "\n"; + echo wordwrap($subtitle,100) . "\n"; + echo str_repeat('-',min(100,max(strlen($title),strlen($subtitle)))) . "\n"; + echo wordwrap($description,100) . "\n\n"; + } } diff --git a/dev/CliTestReporter.php b/dev/CliTestReporter.php new file mode 100644 index 000000000..27d6a4474 --- /dev/null +++ b/dev/CliTestReporter.php @@ -0,0 +1,40 @@ +suiteResults['suites'] as $suite) { + foreach($suite['tests'] as $test) { + $testCount++; + ($test['status'] == 1) ? $passCount++ : $failCount++; + } + } + $result = ($failCount > 0) ? 'fail' : 'pass'; + echo "$testCount tests run: $passCount passes, $failCount fails, and 0 exceptions\n\n"; + } + + public function endTest( PHPUnit_Framework_Test $test, $time) { + parent::endTest($test, $time); + $this->writeTest($this->currentTest); + } + + + protected function writeTest($test) { + if ($test['status'] != 1) { + echo $this->testNameToPhrase($test['name']) . "\n". $test['message'] . "\n"; + echo "In line {$test['exception']['line']} of {$test['exception']['file']}" . "\n\n"; + } + } + +} \ No newline at end of file diff --git a/dev/Debug.php b/dev/Debug.php index f6cf4beba..41c4fe5f3 100644 --- a/dev/Debug.php +++ b/dev/Debug.php @@ -75,7 +75,7 @@ class Debug { if(!Director::isLive()) { if($showHeader) { $caller = Debug::caller(); - if(Director::is_ajax()) + if(Director::is_ajax() || Director::is_cli()) echo "Debug ($caller[class]$caller[type]$caller[function]() in line $caller[line] of " . basename($caller['file']) . ")\n"; else echo "
" . htmlentities($val) . "\n"; } } diff --git a/dev/SapphireTestReporter.php b/dev/SapphireTestReporter.php index 679ea347b..b53263d8a 100644 --- a/dev/SapphireTestReporter.php +++ b/dev/SapphireTestReporter.php @@ -42,27 +42,27 @@ class SapphireTestReporter implements PHPUnit_Framework_TestListener { * Holds array of suites and total number of tests run * @var array */ - private $suiteResults; + protected $suiteResults; /** * Holds data of current suite that is been run * @var array */ - private $currentSuite; + protected $currentSuite; /** * Holds data of current test that is been run * @var array */ - private $currentTest; + protected $currentTest; /** * Whether PEAR Benchmark_Timer is available for timing * @var boolean */ - private $hasTimer; + protected $hasTimer; /** * Holds the PEAR Benchmark_Timer object * @var obj Benchmark_Timer */ - private $timer; + protected $timer; /** * Constructor, checks to see availability of PEAR Benchmark_Timer and @@ -277,7 +277,7 @@ class SapphireTestReporter implements PHPUnit_Framework_TestListener { } - private function testNameToPhrase($name) { + protected function testNameToPhrase($name) { return ucfirst(preg_replace("/([a-z])([A-Z])/", "$1 $2", $name)); } diff --git a/dev/TestRunner.php b/dev/TestRunner.php index cec1e9fe7..7519445a2 100644 --- a/dev/TestRunner.php +++ b/dev/TestRunner.php @@ -47,7 +47,7 @@ class TestRunner extends Controller { function init() { parent::init(); - if (!self::$default_reporter) self::set_reporter('DebugView'); + if (!self::$default_reporter) self::set_reporter(Director::is_cli() ? 'CliDebugView' : 'DebugView'); } public function Link() { @@ -126,7 +126,16 @@ class TestRunner extends Controller { restore_error_handler(); /*, array("reportDirectory" => "/Users/sminnee/phpunit-report")*/ - $reporter = new SapphireTestReporter(); + if(Director::is_cli()) $reporter = new CliTestReporter(); + else $reporter = new SapphireTestReporter(); + + self::$default_reporter->writeHeader("Sapphire Test Runner"); + if (count($classList) > 1) { + self::$default_reporter->writeInfo("All Tests", "Running test cases: " . implode(", ", $classList)); + } else { + self::$default_reporter->writeInfo($classList[0], ""); + } + $results = new PHPUnit_Framework_TestResult(); $results->addListener($reporter); @@ -139,12 +148,6 @@ class TestRunner extends Controller { //$testResult = PHPUnit_TextUI_TestRunner::run($suite); } - self::$default_reporter->writeHeader(); - if (count($classList) > 1) { - self::$default_reporter->writeInfo("All Tests", "Running test cases: " . implode(", ", $classList) .")"); - } else { - self::$default_reporter->writeInfo($classList[0], ""); - } echo '