Permalink
Browse files

adding some coverage for \test\Report

  • Loading branch information...
1 parent 32992d5 commit eb53e19bbec078aa8e2ad471802933bc9de1ba9b @gwoo gwoo committed Nov 25, 2009
@@ -37,7 +37,7 @@ public function __invoke($request, $params, $options = array()) {
'filter' => '/cases|integration|functional/'
));
$menu = $report->reporter->menu($classes, array(
- 'request' => $request, 'format' => 'html', 'tree' => true
+ 'request' => $request, 'tree' => true
));
$template = Libraries::locate('test.reporter.templates', 'layout', array(
@@ -66,13 +66,12 @@ class Report extends \lithium\core\Object {
* Construct Report Object
*
* @param array $config Options array for the test run. Valid options are:
- * - 'case': The fully namespaced test case to be run.
- * - 'group': The fully namespaced test group to be run.
+ * - 'group': The test group with items to be run.
* - 'filters': An array of filters that the test output should be run through.
*/
public function __construct($config = array()) {
$defaults = array(
- 'case' => null,
+ 'title' => null,
'group' => null,
'filters' => array(),
'reporter' => 'text'
@@ -92,12 +91,10 @@ protected function _init() {
throw new Exception("{$format} is not a valid reporter");
}
$this->reporter = new $reporter();
- $this->timer['start'] = microtime(true);
$this->group = $this->_config['group'];
$this->filters = $this->_config['filters'];
$this->title = $this->_config['title'] ?: $this->_config['title'];
$this->run();
- $this->timer['end'] = microtime(true);
}
/**
@@ -106,6 +103,7 @@ protected function _init() {
* @return void
*/
public function run() {
+ $this->timer['start'] = microtime(true);
$tests = $this->group->tests();
foreach ($this->filters as $filter => $options) {
$options = isset($options['apply']) ? $options['apply'] : array();
@@ -117,6 +115,7 @@ public function run() {
$options = isset($options['analyze']) ? $options['analyze'] : array();
$this->results['filters'][$filter] = $filter::analyze($this->results['group'], $options);
}
+ $this->timer['end'] = microtime(true);
}
/**
@@ -63,7 +63,7 @@ public function stats($stats) {
* - tree: true to convert classes to tree structure
*/
public function menu($classes, $options = array()) {
- $defaults = array('request' => '/', 'format' => 'text', 'tree' => false);
+ $defaults = array('request' => '/', 'tree' => false);
$options += $defaults;
if ($options['tree']) {
@@ -9,11 +9,38 @@
namespace lithium\tests\cases\test;
use \lithium\test\Report;
+use \lithium\test\Group;
class ReportTest extends \lithium\test\Unit {
- public function setUp() {
+ public function testInit() {
+ $report = new Report(array(
+ 'title' => '\lithium\tests\mocks\test\MockUnitTest',
+ 'group' => new Group(array('items' => array('\lithium\tests\mocks\test\MockUnitTest')))
+ ));
+ $expected = '\lithium\tests\mocks\test\MockUnitTest';
+ $result = $report->title;
+ $this->assertEqual($expected, $result);
+
+ $expected = 'testNothing';
+ $result = $report->results['group'][0][0]['method'];
+ $this->assertEqual($expected, $result);
+
+ $expected = 'pass';
+ $result = $report->results['group'][0][0]['result'];
+ $this->assertEqual($expected, $result);
+ }
+
+ public function testStats() {
+ $report = new Report(array(
+ 'title' => '\lithium\tests\mocks\test\MockUnitTest',
+ 'group' => new Group(array('items' => array('\lithium\tests\mocks\test\MockUnitTest')))
+ ));
+
+ $expected = "1 / 1 passes\n0 fails and 0 exceptions";
+ $result = $report->stats();
+ $this->assertEqual($expected, $result);
}
}
@@ -16,6 +16,53 @@ public function setUp() {
$this->reporter = new Reporter();
}
+ public function testMenu() {
+ $tests = array('lithium\tests\cases\test\reporter\HtmlTest');
+ $expected = "";
+ $result = $this->reporter->menu($tests);
+ $this->assertEqual($expected, $result);
+ }
+
+ public function testMenuTree() {
+ $tests = array('lithium\tests\cases\test\reporter\HtmlTest');
+ $expected = "";
+ $result = $this->reporter->menu($tests, array('tree' => true));
+ $this->assertEqual($expected, $result);
+ }
+
+ public function testStats() {
+ $stats = array(
+ 'asserts' => 1,
+ 'passes' => array(array(
+ 'line' => 23, 'method' => 'testNothing',
+ 'assertion' => 'assertEqual', 'message' => 'the message',
+ 'class' => 'lithium\tests\cases\test\ReporterTest'
+ )),
+ 'fails' => array(array('method' => 'testNothing')),
+ 'errors' => array(),
+ 'exceptions' => array(),
+ );
+ $expected = "";
+ $result = $this->reporter->stats($stats);
+ $this->assertEqual($expected, $result);
+ }
+
+ public function testStatsWithError() {
+ $stats = array(
+ 'asserts' => 1,
+ 'passes' => array(array(
+ 'line' => 23, 'method' => 'testNothing',
+ 'assertion' => 'assertEqual', 'message' => 'the message',
+ 'class' => 'lithium\tests\cases\test\ReporterTest'
+ )),
+ 'fails' => array(array('method' => 'testNothing')),
+ 'errors' => array('result' => 'fail'),
+ 'exceptions' => array(),
+ );
+ $expected = "";
+ $result = $this->reporter->stats($stats);
+ $this->assertEqual($expected, $result);
+ }
}
?>
@@ -24,7 +24,7 @@ public function setUp() {
public function testMenuWithoutData() {
$expected = '<ul></ul>';
- $result = $this->html->menu(array(), array('format' => 'html'));
+ $result = $this->html->menu(array());
$this->assertEqual($expected, $result);
}
@@ -35,15 +35,15 @@ public function testFormatGroup() {
$expected .= '<ul><li><a href="/test/lithium/tests/cases/core/LibrariesTest">LibrariesTest</a></li>';
$expected .= '</ul></li></ul></li></ul></li></ul>';
$result = $this->html->menu(array('lithium\tests\cases\core\LibrariesTest'), array(
- 'format' => 'html', 'tree' => true, 'request' => new Request()
+ 'tree' => true, 'request' => new Request()
));
$this->assertEqual($expected, $result);
}
public function testFormatCase() {
$tests = array('lithium\tests\cases\test\reporter\HtmlTest');
$expected = '<ul><li><a href="/test/lithium/tests/cases/test/reporter/HtmlTest">HtmlTest</a></li></ul>';
- $result = $this->html->menu($tests, array('format' => 'html', 'request' => new Request()));
+ $result = $this->html->menu($tests, array('request' => new Request()));
$this->assertEqual($expected, $result);
}

0 comments on commit eb53e19

Please sign in to comment.