test_case.php

来自「一款可以和GOOGLE媲美的开源统计系统,运用AJAX.功能强大. 无色提示:」· PHP 代码 · 共 669 行 · 第 1/2 页

PHP
669
字号
        }        /**         *    Sends a formatted dump of a variable to the         *    test suite for those emergency debugging         *    situations.         *    @param mixed $variable    Variable to display.         *    @param string $message    Message to display.         *    @return mixed             The original variable.         *    @access public         */        function dump($variable, $message = false) {            $dumper = $this->_reporter->getDumper();            $formatted = $dumper->dump($variable);            if ($message) {                $formatted = $message . "\n" . $formatted;            }            $this->_reporter->paintFormattedMessage($formatted);            return $variable;        }        /**         *    @deprecated         */        function sendMessage($message) {            $this->_reporter->PaintMessage($message);        }        /**         *    Accessor for the number of subtests.         *    @return integer           Number of test cases.         *    @access public         *    @static         */        function getSize() {            return 1;        }    }    /**     *  Helps to extract test cases automatically from a file.     */    class SimpleFileLoader {        /**         *    Builds a test suite from a library of test cases.         *    The new suite is composed into this one.         *    @param string $test_file        File name of library with         *                                    test case classes.         *    @return TestSuite               The new test suite.         *    @access public         */        function &load($test_file) {            $existing_classes = get_declared_classes();            include_once($test_file);            $classes = $this->selectRunnableTests(                    array_diff(get_declared_classes(), $existing_classes));            $suite = &$this->createSuiteFromClasses($test_file, $classes);            return $suite;        }        /**         *    Calculates the incoming test cases. Skips abstract         *    and ignored classes.         *    @param array $candidates   Candidate classes.         *    @return array              New classes which are test         *                               cases that shouldn't be ignored.         *    @access public         */        function selectRunnableTests($candidates) {            $classes = array();            foreach ($candidates as $class) {                if (TestSuite::getBaseTestCase($class)) {                    $reflection = new SimpleReflection($class);                    if ($reflection->isAbstract()) {                        SimpleTest::ignore($class);                    }                    $classes[] = $class;                }            }            return $classes;        }        /**         *    Builds a test suite from a class list.         *    @param string $title       Title of new group.         *    @param array $classes      Test classes.         *    @return TestSuite          Group loaded with the new         *                               test cases.         *    @access public         */        function &createSuiteFromClasses($title, $classes) {            if (count($classes) == 0) {                $suite = &new BadTestSuite($title, "No runnable test cases in [$title]");                return $suite;            }            SimpleTest::ignoreParentsIfIgnored($classes);            $suite = &new TestSuite($title);            foreach ($classes as $class) {                if (! SimpleTest::isIgnored($class)) {                    $suite->addTestClass($class);                }            }            return $suite;        }    }    /**     *    This is a composite test class for combining     *    test cases and other RunnableTest classes into     *    a group test.	 *    @package		SimpleTest	 *    @subpackage	UnitTester     */    class TestSuite {        var $_label;        var $_test_cases;        /**         *    Sets the name of the test suite.         *    @param string $label    Name sent at the start and end         *                            of the test.         *    @access public         */        function TestSuite($label = false) {            $this->_label = $label;            $this->_test_cases = array();        }        /**         *    Accessor for the test name for subclasses. If the suite		 *    wraps a single test case the label defaults to the name of that test.         *    @return string           Name of the test.         *    @access public         */        function getLabel() {			if (! $this->_label) {				return ($this->getSize() == 1) ?                        get_class($this->_test_cases[0]) : get_class($this);			} else {				return $this->_label;			}        }        /**         *    @deprecated         */        function addTestCase(&$test_case) {            $this->_test_cases[] = &$test_case;        }        /**         *    @deprecated         */        function addTestClass($class) {            if (TestSuite::getBaseTestCase($class) == 'testsuite') {                $this->_test_cases[] = &new $class();            } else {                $this->_test_cases[] = $class;            }        }        /**         *    Adds a test into the suite by instance or class. The class will         *    be instantiated if it's a test suite.         *    @param SimpleTestCase $test_case  Suite or individual test         *                                      case implementing the         *                                      runnable test interface.         *    @access public         */        function add(&$test_case) {            if (! is_string($test_case)) {                $this->_test_cases[] = &$test_case;            } elseif (TestSuite::getBaseTestCase($class) == 'testsuite') {                $this->_test_cases[] = &new $class();            } else {                $this->_test_cases[] = $class;            }        }        /**         *    @deprecated         */        function addTestFile($test_file) {            $this->addFile($test_file);        }        /**         *    Builds a test suite from a library of test cases.         *    The new suite is composed into this one.         *    @param string $test_file        File name of library with         *                                    test case classes.         *    @access public         */        function addFile($test_file) {            $extractor = new SimpleFileLoader();            $this->add($extractor->load($test_file));        }        /**         *    Delegates to a visiting collector to add test         *    files.         *    @param string $path                  Path to scan from.         *    @param SimpleCollector $collector    Directory scanner.         *    @access public         */        function collect($path, &$collector) {            $collector->collect($this, $path);        }        /**         *    Invokes run() on all of the held test cases, instantiating         *    them if necessary.         *    @param SimpleReporter $reporter    Current test reporter.         *    @access public         */        function run(&$reporter) {            $reporter->paintGroupStart($this->getLabel(), $this->getSize());            for ($i = 0, $count = count($this->_test_cases); $i < $count; $i++) {                if (is_string($this->_test_cases[$i])) {                    $class = $this->_test_cases[$i];                    $test = &new $class();                    $test->run($reporter);                    unset($test);                } else {                    $this->_test_cases[$i]->run($reporter);                }            }            $reporter->paintGroupEnd($this->getLabel());            return $reporter->getStatus();        }        /**         *    Number of contained test cases.         *    @return integer     Total count of cases in the group.         *    @access public         */        function getSize() {            $count = 0;            foreach ($this->_test_cases as $case) {                if (is_string($case)) {                    $count++;                } else {                    $count += $case->getSize();                }            }            return $count;        }        /**         *    Test to see if a class is derived from the         *    SimpleTestCase class.         *    @param string $class     Class name.         *    @access public         *    @static         */        function getBaseTestCase($class) {            while ($class = get_parent_class($class)) {                $class = strtolower($class);                if ($class == 'simpletestcase' || $class == 'testsuite') {                    return $class;                }            }            return false;        }    }    /**	 *    @package		SimpleTest	 *    @subpackage	UnitTester     *    @deprecated     */    class GroupTest extends TestSuite { }    /**     *    This is a failing group test for when a test suite hasn't     *    loaded properly.	 *    @package		SimpleTest	 *    @subpackage	UnitTester     */    class BadTestSuite {        var $_label;        var $_error;        /**         *    Sets the name of the test suite and error message.         *    @param string $label    Name sent at the start and end         *                            of the test.         *    @access public         */        function BadTestSuite($label, $error) {            $this->_label = $label;            $this->_error = $error;        }        /**         *    Accessor for the test name for subclasses.         *    @return string           Name of the test.         *    @access public         */        function getLabel() {            return $this->_label;        }        /**         *    Sends a single error to the reporter.         *    @param SimpleReporter $reporter    Current test reporter.         *    @access public         */        function run(&$reporter) {            $reporter->paintGroupStart($this->getLabel(), $this->getSize());            $reporter->paintFail('Bad TestSuite [' . $this->getLabel() .                    '] with error [' . $this->_error . ']');            $reporter->paintGroupEnd($this->getLabel());            return $reporter->getStatus();        }        /**         *    Number of contained test cases. Always zero.         *    @return integer     Total count of cases in the group.         *    @access public         */        function getSize() {            return 0;        }    }    /**	 *    @package		SimpleTest	 *    @subpackage	UnitTester     *    @deprecated     */    class BadGroupTest extends BadTestSuite { }?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?