Skip to content
Browse files

adding skip rendering to \test

  • Loading branch information...
1 parent c70ea89 commit b3601fc58bb9a327ebe5f136ebd150824648ae09 @gwoo gwoo committed Feb 15, 2010
View
11 app/webroot/css/debug.css
@@ -81,7 +81,7 @@ div.test-result-fail {
border-color: #990000;
}
-div.test-assert, div.test-exception {
+div.test-assert, div.test-exception, div.test-skip {
margin: 4px 0;
padding: 4px 8px;
color: #000000;
@@ -117,6 +117,15 @@ div.test-exception span.trace {
border-left: 1px solid #C09090;
}
+div.test-skip {
+ border-color: #000000;
+ background-color: #CCC;
+}
+
+div.test-skip span.content {
+ display: block;
+ font-style: italic;
+}
/*--- SQL Dumps ---*/
.lithium-sql-log table {
background: #f4f4f4;
View
6 libraries/lithium/test/Report.php
@@ -160,10 +160,10 @@ public function stats() {
'passes' => array(),
'fails' => array(),
'exceptions' => array(),
- 'errors' => array()
+ 'errors' => array(),
+ 'skips' => array()
);
$result = empty($result[0]) ? array($result) : $result;
-
foreach ($result as $response) {
if (empty($response['result'])) {
continue;
@@ -178,7 +178,7 @@ public function stats() {
if (in_array($result, array('pass', 'fail'))) {
$stats['asserts']++;
}
- if (in_array($result, array('pass', 'fail', 'exception'))) {
+ if (in_array($result, array('pass', 'fail', 'exception', 'skip'))) {
$stats[Inflector::pluralize($result)][] = $response;
}
}
View
22 libraries/lithium/test/Reporter.php
@@ -24,6 +24,7 @@ public function stats($stats) {
'fails' => array(),
'errors' => array(),
'exceptions' => array(),
+ 'skips' => array()
);
$stats = (array) $stats + $defaults;
@@ -36,17 +37,16 @@ function($value) { return is_array($value) ? count($value) : $value; },
$result[] = $this->_result($count + compact('success'));
foreach ((array) $stats['errors'] as $error) {
- switch ($error['result']) {
- case 'fail':
- $error += array('class' => 'unknown', 'method' => 'unknown');
- $result[] = $this->_fail($error);
- break;
- case 'exception':
- $result[] = $this->_exception($error);
- break;
- }
+ $error = array_merge(
+ array('class' => 'unknown', 'method' => 'unknown'), (array) $error
+ );
+ $method = "_{$error['result']}";
+ $result[] = $this->{$method}($error);
+ }
+ foreach ((array) $stats['skips'] as $skip) {
+ $result[] = $this->_skip($skip);
}
- return join("\n", $result);
+ return trim(join("\n", $result));
}
/**
@@ -133,6 +133,8 @@ protected function _fail($data) {}
protected function _exception($data) {}
+ protected function _skip($data) {}
+
protected function _item($data) {}
}
View
17 libraries/lithium/test/Unit.php
@@ -92,11 +92,8 @@ public function run($options = array()) {
try {
$this->skip();
} catch (Exception $e) {
- if (preg_match('/^Skipped test/', $e->getMessage())) {
- $this->_result('skip', array());
- }
- $this->_handleException($e, __LINE__ - 5);
- return;
+ $this->_handleException($e);
+ return $this->_results;
}
set_error_handler($options['handler']);
@@ -523,7 +520,6 @@ protected function _result($type, $info, $options = array()) {
$info = (array('result' => $type) + $info);
$defaults = array();
$options += $defaults;
-
if ($this->_reporter) {
$filtered = $this->_reporter->__invoke($info);
$info = is_array($filtered) ? $filtered : $info;
@@ -543,6 +539,7 @@ protected function _runTestMethod($method, $options) {
$this->setUp();
} catch (Exception $e) {
$this->_handleException($e, __LINE__ - 2);
+ return $this->_results;
}
$params = compact('options', 'method');
@@ -552,13 +549,7 @@ protected function _runTestMethod($method, $options) {
$lineFlag = __LINE__ + 1;
$self->$method();
} catch (Exception $e) {
- if (preg_match('/^Skipped test/', $e->getMessage())) {
- $self->invokeMethod('_result', array('skip', array(
- 'message' => $e->getMessage()
- )));
- } else {
- $self->invokeMethod('_handleException', array($e, $lineFlag));
- }
+ $self->invokeMethod('_handleException', array($e));
}
});
$this->tearDown();
View
11 libraries/lithium/test/reporter/Html.php
@@ -54,6 +54,17 @@ protected function _exception($error) {
return join("", $exception);
}
+ protected function _skip($skip) {
+ $result = array(
+ '<div class="test-skip">',
+ "Skip {$skip['trace'][1]['class']}::{$skip['trace'][1]['function']}() ",
+ "on line {$skip['trace'][1]['line']}: ",
+ "<span class=\"content\">{$skip['message']}</span>",
+ "</div>"
+ );
+ return join("", $result);
+ }
+
public function filters($filters) {
$result = array();
foreach ((array) $filters as $class => $data) {
View
9 libraries/lithium/test/reporter/Text.php
@@ -43,6 +43,15 @@ protected function _exception($error) {
return join("\n", $exception);
}
+ protected function _skip($skip) {
+ $result = array(
+ "Skip {$skip['trace'][1]['class']}::{$skip['trace'][1]['function']}() ",
+ "on line {$skip['trace'][1]['line']}:\n",
+ "{$skip['message']}",
+ );
+ return join("", $result);
+ }
+
public function filters($filters) {
$output = array();
View
2 libraries/lithium/tests/cases/test/ReporterTest.php
@@ -56,7 +56,7 @@ public function testStatsWithError() {
'class' => 'lithium\tests\cases\test\reporter\BaseTest'
)),
'fails' => array(array('method' => 'testNothing')),
- 'errors' => array('result' => 'fail'),
+ 'errors' => array(array('result' => 'fail')),
'exceptions' => array(),
);
$expected = "";
View
23 libraries/lithium/tests/cases/test/UnitTest.php
@@ -14,10 +14,6 @@ public function compare($type, $expected, $result = null) {
return $this->_compare($type, $expected, $result);
}
- /**
- * @todo Figure out a way to expect failures
- * @return void
- */
public function testBaseAssertions() {
$this->assert(true);
//$this->assert(false);
@@ -37,12 +33,6 @@ public function testAssertEqualNumeric() {
$this->assertEqual($expected, $result);
}
- /**
- * undocumented function
- *
- * @return void
- * @todo See @todo above.
- */
public function testAssertEqualNumericFail() {
$result = array(1, 2);
$expected = array(1, 2, 3);
@@ -88,7 +78,8 @@ public function testTestMethods() {
'testBaseAssertions', 'testCompare', 'testAssertEqualNumeric',
'testAssertEqualNumericFail', 'testAssertEqualAssociativeArray',
'testAssertEqualThreeDFail', 'testAssertIdentical', 'testTestMethods',
- 'testCleanUp', 'testCleanUpWithFullPath', 'testCleanUpWithRelativePath'
+ 'testCleanUp', 'testCleanUpWithFullPath', 'testCleanUpWithRelativePath',
+ 'testSkipIf'
);
$this->assertEqual($expected, $this->methods());
}
@@ -136,6 +127,16 @@ public function testCleanUpWithRelativePath() {
$this->_cleanUp();
}
+
+ public function testSkipIf() {
+ try {
+ $this->skipIf(true, 'skip me');
+ } catch (\Exception $e) {
+ $result = $e->getMessage();
+ }
+ $expected = 'skip me';
+ $this->assertEqual($expected, $result);
+ }
}
?>
View
25 libraries/lithium/tests/cases/test/reporter/HtmlTest.php
@@ -18,6 +18,8 @@ class HtmlTest extends \lithium\test\Unit {
public function setUp() {
$this->html = new Html();
$this->mock = new MockHtml();
+ $this->_routes = Router::get();
+ Router::connect(null);
Router::connect('/test/{:args}', array('controller' => '\lithium\test\Controller'));
Router::connect('/test', array('controller' => '\lithium\test\Controller'));
$this->request = new Request(array(
@@ -26,6 +28,14 @@ public function setUp() {
));
}
+ public function tearDown() {
+ Router::connect(null);
+
+ foreach ($this->_routes as $route) {
+ Router::connect($route);
+ }
+ }
+
public function testMenuWithoutData() {
$expected = '<ul></ul>';
$result = $this->html->menu(array());
@@ -105,6 +115,21 @@ public function testException() {
$result = $this->mock->exception($exception);
$this->assertEqual($expected, $result);
}
+
+ public function testSkip() {
+ $exception = array(
+ 'trace' => array(array(), array(
+ 'class' => 'MockTest', 'function' => 'testNothing', 'line' => 8
+ )),
+ 'message' => 'skip this test',
+ );
+ $expected = "<div class=\"test-skip\">";
+ $expected .= "Skip MockTest::testNothing() on line 8: ";
+ $expected .= "<span class=\"content\">skip this test</span>";
+ $expected .= "</div>";
+ $result = $this->mock->skip($exception);
+ $this->assertEqual($expected, $result);
+ }
}
?>
View
13 libraries/lithium/tests/cases/test/reporter/TextTest.php
@@ -58,6 +58,19 @@ public function testException() {
$result = $this->mock->exception($exception);
$this->assertEqual($expected, $result);
}
+
+ public function testSkip() {
+ $exception = array(
+ 'trace' => array(array(), array(
+ 'class' => 'MockTest', 'function' => 'testNothing', 'line' => 8
+ )),
+ 'message' => 'skip this test',
+ );
+ $expected = "Skip MockTest::testNothing() on line 8:\n";
+ $expected .= "skip this test";
+ $result = $this->mock->skip($exception);
+ $this->assertEqual($expected, $result);
+ }
}
?>
View
4 libraries/lithium/tests/mocks/test/reporter/MockHtml.php
@@ -21,6 +21,10 @@ public function fail($fails) {
public function exception($exceptions) {
return $this->_exception($exceptions);
}
+
+ public function skip($skips) {
+ return $this->_skip($skips);
+ }
}
?>
View
4 libraries/lithium/tests/mocks/test/reporter/MockText.php
@@ -21,6 +21,10 @@ public function fail($fails) {
public function exception($exceptions) {
return $this->_exception($exceptions);
}
+
+ public function skip($skips) {
+ return $this->_skip($skips);
+ }
}
?>

0 comments on commit b3601fc

Please sign in to comment.
Something went wrong with that request. Please try again.