aboutsummaryrefslogtreecommitdiff
path: root/vendors/simpletest/default_reporter.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-02 18:40:04 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-02 18:40:04 +0000
commit322bb9cd2be9e51422cb2b82684692e825c2bfb7 (patch)
tree1e8e75c1ff0c47d6eda9db114a13dfa2b83adf72 /vendors/simpletest/default_reporter.php
parent4ffb02ad9c1b95013a0fbf97cefde827600ecc3f (diff)
downloadelgg-322bb9cd2be9e51422cb2b82684692e825c2bfb7.tar.gz
elgg-322bb9cd2be9e51422cb2b82684692e825c2bfb7.tar.bz2
Added simpletest and start of unit tests.
git-svn-id: http://code.elgg.org/elgg/trunk@3503 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'vendors/simpletest/default_reporter.php')
-rwxr-xr-xvendors/simpletest/default_reporter.php133
1 files changed, 133 insertions, 0 deletions
diff --git a/vendors/simpletest/default_reporter.php b/vendors/simpletest/default_reporter.php
new file mode 100755
index 000000000..bd4c6a190
--- /dev/null
+++ b/vendors/simpletest/default_reporter.php
@@ -0,0 +1,133 @@
+<?php
+/**
+ * Optional include file for SimpleTest
+ * @package SimpleTest
+ * @subpackage UnitTester
+ * @version $Id: default_reporter.php 1704 2008-03-25 00:47:04Z lastcraft $
+ */
+
+/**#@+
+ * include other SimpleTest class files
+ */
+require_once(dirname(__FILE__) . '/simpletest.php');
+require_once(dirname(__FILE__) . '/scorer.php');
+require_once(dirname(__FILE__) . '/reporter.php');
+require_once(dirname(__FILE__) . '/xml.php');
+/**#@-*/
+
+/**
+ * Parser for command line arguments. Extracts
+ * the a specific test to run and engages XML
+ * reporting when necessary.
+ * @package SimpleTest
+ * @subpackage UnitTester
+ */
+class SimpleCommandLineParser {
+ var $_to_property = array(
+ 'case' => '_case', 'c' => '_case',
+ 'test' => '_test', 't' => '_test',
+ 'xml' => '_xml', 'x' => '_xml');
+ var $_case = '';
+ var $_test = '';
+ var $_xml = false;
+ var $_no_skips = false;
+
+ /**
+ * Parses raw command line arguments into object properties.
+ * @param string $arguments Raw commend line arguments.
+ */
+ function SimpleCommandLineParser($arguments) {
+ if (! is_array($arguments)) {
+ return;
+ }
+ foreach ($arguments as $i => $argument) {
+ if (preg_match('/^--?(test|case|t|c)=(.+)$/', $argument, $matches)) {
+ $property = $this->_to_property[$matches[1]];
+ $this->$property = $matches[2];
+ } elseif (preg_match('/^--?(test|case|t|c)$/', $argument, $matches)) {
+ $property = $this->_to_property[$matches[1]];
+ if (isset($arguments[$i + 1])) {
+ $this->$property = $arguments[$i + 1];
+ }
+ } elseif (preg_match('/^--?(xml|x)$/', $argument)) {
+ $this->_xml = true;
+ } elseif (preg_match('/^--?(no-skip|no-skips|s)$/', $argument)) {
+ $this->_no_skips = true;
+ }
+ }
+ }
+
+ /**
+ * Run only this test.
+ * @return string Test name to run.
+ * @access public
+ */
+ function getTest() {
+ return $this->_test;
+ }
+
+ /**
+ * Run only this test suite.
+ * @return string Test class name to run.
+ * @access public
+ */
+ function getTestCase() {
+ return $this->_case;
+ }
+
+ /**
+ * Output should be XML or not.
+ * @return boolean True if XML desired.
+ * @access public
+ */
+ function isXml() {
+ return $this->_xml;
+ }
+
+ /**
+ * Output should suppress skip messages.
+ * @return boolean True for no skips.
+ * @access public
+ */
+ function noSkips() {
+ return $this->_no_skips;
+ }
+}
+
+/**
+ * The default reporter used by SimpleTest's autorun
+ * feature. The actual reporters used are dependency
+ * injected and can be overridden.
+ * @package SimpleTest
+ * @subpackage UnitTester
+ */
+class DefaultReporter extends SimpleReporterDecorator {
+
+ /**
+ * Assembles the appopriate reporter for the environment.
+ */
+ function DefaultReporter() {
+ if (SimpleReporter::inCli()) {
+ global $argv;
+ $parser = new SimpleCommandLineParser($argv);
+ $interfaces = $parser->isXml() ? array('XmlReporter') : array('TextReporter');
+ $reporter = &new SelectiveReporter(
+ SimpleTest::preferred($interfaces),
+ $parser->getTestCase(),
+ $parser->getTest());
+ if ($parser->noSkips()) {
+ $reporter = &new NoSkipsReporter($reporter);
+ }
+ } else {
+ $reporter = &new SelectiveReporter(
+ SimpleTest::preferred('HtmlReporter'),
+ @$_GET['c'],
+ @$_GET['t']);
+ if (@$_GET['skips'] == 'no' || @$_GET['show-skips'] == 'no') {
+ $reporter = &new NoSkipsReporter($reporter);
+ }
+ }
+ $this->SimpleReporterDecorator($reporter);
+ }
+}
+?> \ No newline at end of file