mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Added a backport of Limesurvey CI Remote Control 2 functionality for adding a response.
Can be used to insert a new response into a questionnaire via XML-RPC Added xmlrpc package from: http://phpxmlrpc.sourceforge.net (new BSD licence compatible with GPL)
This commit is contained in:
400
include/limesurvey/admin/classes/xmlrpc/test/PHPUnit/Assert.php
Normal file
400
include/limesurvey/admin/classes/xmlrpc/test/PHPUnit/Assert.php
Normal file
@@ -0,0 +1,400 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* PHP Version 4
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Testing
|
||||
* @package PHPUnit
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: Assert.php 2 2009-03-16 20:22:51Z ggiunta $
|
||||
* @link http://pear.php.net/package/PHPUnit
|
||||
* @since File available since Release 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* A set of assert methods.
|
||||
*
|
||||
* @category Testing
|
||||
* @package PHPUnit
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/PHPUnit
|
||||
* @since Class available since Release 1.0.0
|
||||
*/
|
||||
class PHPUnit_Assert {
|
||||
/**
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
var $_looselyTyped = FALSE;
|
||||
|
||||
/**
|
||||
* Asserts that a haystack contains a needle.
|
||||
*
|
||||
* @param mixed
|
||||
* @param mixed
|
||||
* @param string
|
||||
* @access public
|
||||
* @since Method available since Release 1.1.0
|
||||
*/
|
||||
function assertContains($needle, $haystack, $message = '') {
|
||||
if (is_string($needle) && is_string($haystack)) {
|
||||
$this->assertTrue(strpos($haystack, $needle) !== FALSE, $message);
|
||||
}
|
||||
|
||||
else if (is_array($haystack) && !is_object($needle)) {
|
||||
$this->assertTrue(in_array($needle, $haystack), $message);
|
||||
}
|
||||
|
||||
else {
|
||||
$this->fail('Unsupported parameter passed to assertContains().');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a haystack does not contain a needle.
|
||||
*
|
||||
* @param mixed
|
||||
* @param mixed
|
||||
* @param string
|
||||
* @access public
|
||||
* @since Method available since Release 1.1.0
|
||||
*/
|
||||
function assertNotContains($needle, $haystack, $message = '') {
|
||||
if (is_string($needle) && is_string($haystack)) {
|
||||
$this->assertFalse(strpos($haystack, $needle) !== FALSE, $message);
|
||||
}
|
||||
|
||||
else if (is_array($haystack) && !is_object($needle)) {
|
||||
$this->assertFalse(in_array($needle, $haystack), $message);
|
||||
}
|
||||
|
||||
else {
|
||||
$this->fail('Unsupported parameter passed to assertNotContains().');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two variables are equal.
|
||||
*
|
||||
* @param mixed
|
||||
* @param mixed
|
||||
* @param string
|
||||
* @param mixed
|
||||
* @access public
|
||||
*/
|
||||
function assertEquals($expected, $actual, $message = '', $delta = 0) {
|
||||
if ((is_array($actual) && is_array($expected)) ||
|
||||
(is_object($actual) && is_object($expected))) {
|
||||
if (is_array($actual) && is_array($expected)) {
|
||||
ksort($actual);
|
||||
ksort($expected);
|
||||
}
|
||||
|
||||
if ($this->_looselyTyped) {
|
||||
$actual = $this->_convertToString($actual);
|
||||
$expected = $this->_convertToString($expected);
|
||||
}
|
||||
|
||||
$actual = serialize($actual);
|
||||
$expected = serialize($expected);
|
||||
|
||||
$message = sprintf(
|
||||
'%sexpected %s, actual %s',
|
||||
|
||||
!empty($message) ? $message . ' ' : '',
|
||||
$expected,
|
||||
$actual
|
||||
);
|
||||
|
||||
if ($actual !== $expected) {
|
||||
return $this->fail($message);
|
||||
}
|
||||
}
|
||||
|
||||
elseif (is_numeric($actual) && is_numeric($expected)) {
|
||||
$message = sprintf(
|
||||
'%sexpected %s%s, actual %s',
|
||||
|
||||
!empty($message) ? $message . ' ' : '',
|
||||
$expected,
|
||||
($delta != 0) ? ('+/- ' . $delta) : '',
|
||||
$actual
|
||||
);
|
||||
|
||||
if (!($actual >= ($expected - $delta) && $actual <= ($expected + $delta))) {
|
||||
return $this->fail($message);
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
$message = sprintf(
|
||||
'%sexpected %s, actual %s',
|
||||
|
||||
!empty($message) ? $message . ' ' : '',
|
||||
$expected,
|
||||
$actual
|
||||
);
|
||||
|
||||
if ($actual !== $expected) {
|
||||
return $this->fail($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two variables reference the same object.
|
||||
* This requires the Zend Engine 2 to work.
|
||||
*
|
||||
* @param object
|
||||
* @param object
|
||||
* @param string
|
||||
* @access public
|
||||
* @deprecated
|
||||
*/
|
||||
function assertSame($expected, $actual, $message = '') {
|
||||
if (!version_compare(phpversion(), '5.0.0', '>=')) {
|
||||
$this->fail('assertSame() only works with PHP >= 5.0.0.');
|
||||
}
|
||||
|
||||
if ((is_object($expected) || is_null($expected)) &&
|
||||
(is_object($actual) || is_null($actual))) {
|
||||
$message = sprintf(
|
||||
'%sexpected two variables to reference the same object',
|
||||
|
||||
!empty($message) ? $message . ' ' : ''
|
||||
);
|
||||
|
||||
if ($expected !== $actual) {
|
||||
return $this->fail($message);
|
||||
}
|
||||
} else {
|
||||
$this->fail('Unsupported parameter passed to assertSame().');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two variables do not reference the same object.
|
||||
* This requires the Zend Engine 2 to work.
|
||||
*
|
||||
* @param object
|
||||
* @param object
|
||||
* @param string
|
||||
* @access public
|
||||
* @deprecated
|
||||
*/
|
||||
function assertNotSame($expected, $actual, $message = '') {
|
||||
if (!version_compare(phpversion(), '5.0.0', '>=')) {
|
||||
$this->fail('assertNotSame() only works with PHP >= 5.0.0.');
|
||||
}
|
||||
|
||||
if ((is_object($expected) || is_null($expected)) &&
|
||||
(is_object($actual) || is_null($actual))) {
|
||||
$message = sprintf(
|
||||
'%sexpected two variables to reference different objects',
|
||||
|
||||
!empty($message) ? $message . ' ' : ''
|
||||
);
|
||||
|
||||
if ($expected === $actual) {
|
||||
return $this->fail($message);
|
||||
}
|
||||
} else {
|
||||
$this->fail('Unsupported parameter passed to assertNotSame().');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a variable is not NULL.
|
||||
*
|
||||
* @param mixed
|
||||
* @param string
|
||||
* @access public
|
||||
*/
|
||||
function assertNotNull($actual, $message = '') {
|
||||
$message = sprintf(
|
||||
'%sexpected NOT NULL, actual NULL',
|
||||
|
||||
!empty($message) ? $message . ' ' : ''
|
||||
);
|
||||
|
||||
if (is_null($actual)) {
|
||||
return $this->fail($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a variable is NULL.
|
||||
*
|
||||
* @param mixed
|
||||
* @param string
|
||||
* @access public
|
||||
*/
|
||||
function assertNull($actual, $message = '') {
|
||||
$message = sprintf(
|
||||
'%sexpected NULL, actual NOT NULL',
|
||||
|
||||
!empty($message) ? $message . ' ' : ''
|
||||
);
|
||||
|
||||
if (!is_null($actual)) {
|
||||
return $this->fail($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a condition is true.
|
||||
*
|
||||
* @param boolean
|
||||
* @param string
|
||||
* @access public
|
||||
*/
|
||||
function assertTrue($condition, $message = '') {
|
||||
$message = sprintf(
|
||||
'%sexpected TRUE, actual FALSE',
|
||||
|
||||
!empty($message) ? $message . ' ' : ''
|
||||
);
|
||||
|
||||
if (!$condition) {
|
||||
return $this->fail($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a condition is false.
|
||||
*
|
||||
* @param boolean
|
||||
* @param string
|
||||
* @access public
|
||||
*/
|
||||
function assertFalse($condition, $message = '') {
|
||||
$message = sprintf(
|
||||
'%sexpected FALSE, actual TRUE',
|
||||
|
||||
!empty($message) ? $message . ' ' : ''
|
||||
);
|
||||
|
||||
if ($condition) {
|
||||
return $this->fail($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a string matches a given regular expression.
|
||||
*
|
||||
* @param string
|
||||
* @param string
|
||||
* @param string
|
||||
* @access public
|
||||
*/
|
||||
function assertRegExp($pattern, $string, $message = '') {
|
||||
$message = sprintf(
|
||||
'%s"%s" does not match pattern "%s"',
|
||||
|
||||
!empty($message) ? $message . ' ' : '',
|
||||
$string,
|
||||
$pattern
|
||||
);
|
||||
|
||||
if (!preg_match($pattern, $string)) {
|
||||
return $this->fail($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a string does not match a given regular expression.
|
||||
*
|
||||
* @param string
|
||||
* @param string
|
||||
* @param string
|
||||
* @access public
|
||||
* @since Method available since Release 1.1.0
|
||||
*/
|
||||
function assertNotRegExp($pattern, $string, $message = '') {
|
||||
$message = sprintf(
|
||||
'%s"%s" matches pattern "%s"',
|
||||
|
||||
!empty($message) ? $message . ' ' : '',
|
||||
$string,
|
||||
$pattern
|
||||
);
|
||||
|
||||
if (preg_match($pattern, $string)) {
|
||||
return $this->fail($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a variable is of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param mixed $actual
|
||||
* @param optional string $message
|
||||
* @access public
|
||||
*/
|
||||
function assertType($expected, $actual, $message = '') {
|
||||
return $this->assertEquals(
|
||||
$expected,
|
||||
gettype($actual),
|
||||
$message
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a value to a string.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @access private
|
||||
*/
|
||||
function _convertToString($value) {
|
||||
foreach ($value as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
$value[$k] = $this->_convertToString($value[$k]);
|
||||
} else {
|
||||
settype($value[$k], 'string');
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $looselyTyped
|
||||
* @access public
|
||||
*/
|
||||
function setLooselyTyped($looselyTyped) {
|
||||
if (is_bool($looselyTyped)) {
|
||||
$this->_looselyTyped = $looselyTyped;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fails a test with the given message.
|
||||
*
|
||||
* @param string
|
||||
* @access protected
|
||||
* @abstract
|
||||
*/
|
||||
function fail($message = '') { /* abstract */ }
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* c-hanging-comment-ender-p: nil
|
||||
* End:
|
||||
*/
|
||||
?>
|
||||
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* PHP Version 4
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Testing
|
||||
* @package PHPUnit
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: TestCase.php 2 2009-03-16 20:22:51Z ggiunta $
|
||||
* @link http://pear.php.net/package/PHPUnit
|
||||
* @since File available since Release 1.0.0
|
||||
*/
|
||||
|
||||
require_once 'PHPUnit/Assert.php';
|
||||
require_once 'PHPUnit/TestResult.php';
|
||||
|
||||
/**
|
||||
* A TestCase defines the fixture to run multiple tests.
|
||||
*
|
||||
* To define a TestCase
|
||||
*
|
||||
* 1) Implement a subclass of PHPUnit_TestCase.
|
||||
* 2) Define instance variables that store the state of the fixture.
|
||||
* 3) Initialize the fixture state by overriding setUp().
|
||||
* 4) Clean-up after a test by overriding tearDown().
|
||||
*
|
||||
* Each test runs in its own fixture so there can be no side effects
|
||||
* among test runs.
|
||||
*
|
||||
* Here is an example:
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* class MathTest extends PHPUnit_TestCase {
|
||||
* var $fValue1;
|
||||
* var $fValue2;
|
||||
*
|
||||
* function MathTest($name) {
|
||||
* $this->PHPUnit_TestCase($name);
|
||||
* }
|
||||
*
|
||||
* function setUp() {
|
||||
* $this->fValue1 = 2;
|
||||
* $this->fValue2 = 3;
|
||||
* }
|
||||
* }
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* For each test implement a method which interacts with the fixture.
|
||||
* Verify the expected results with assertions specified by calling
|
||||
* assert with a boolean.
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* function testPass() {
|
||||
* $this->assertTrue($this->fValue1 + $this->fValue2 == 5);
|
||||
* }
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* @category Testing
|
||||
* @package PHPUnit
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/PHPUnit
|
||||
* @since Class available since Release 1.0.0
|
||||
*/
|
||||
class PHPUnit_TestCase extends PHPUnit_Assert {
|
||||
/**
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
var $_failed = FALSE;
|
||||
|
||||
/**
|
||||
* The name of the test case.
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_name = '';
|
||||
|
||||
/**
|
||||
* PHPUnit_TestResult object
|
||||
*
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $_result;
|
||||
|
||||
/**
|
||||
* Constructs a test case with the given name.
|
||||
*
|
||||
* @param string
|
||||
* @access public
|
||||
*/
|
||||
function PHPUnit_TestCase($name = FALSE) {
|
||||
if ($name !== FALSE) {
|
||||
$this->setName($name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of test cases executed by run(TestResult result).
|
||||
*
|
||||
* @return integer
|
||||
* @access public
|
||||
*/
|
||||
function countTestCases() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of a TestCase.
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function getName() {
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the test case and collects the results in a given TestResult object.
|
||||
*
|
||||
* @param object
|
||||
* @return object
|
||||
* @access public
|
||||
*/
|
||||
function run(&$result) {
|
||||
$this->_result = &$result;
|
||||
$this->_result->run($this);
|
||||
|
||||
return $this->_result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the bare test sequence.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function runBare() {
|
||||
$this->setUp();
|
||||
$this->runTest();
|
||||
$this->tearDown();
|
||||
$this->pass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to run the test and assert its state.
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
function runTest() {
|
||||
call_user_func(
|
||||
array(
|
||||
&$this,
|
||||
$this->_name
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of a TestCase.
|
||||
*
|
||||
* @param string
|
||||
* @access public
|
||||
*/
|
||||
function setName($name) {
|
||||
$this->_name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the test case.
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function toString() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default TestResult object.
|
||||
*
|
||||
* @return object
|
||||
* @access protected
|
||||
*/
|
||||
function &createResult() {
|
||||
return new PHPUnit_TestResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fails a test with the given message.
|
||||
*
|
||||
* @param string
|
||||
* @access protected
|
||||
*/
|
||||
function fail($message = '') {
|
||||
if (function_exists('debug_backtrace')) {
|
||||
$trace = debug_backtrace();
|
||||
|
||||
if (isset($trace['1']['file'])) {
|
||||
$message = sprintf(
|
||||
"%s in %s:%s",
|
||||
|
||||
$message,
|
||||
$trace['1']['file'],
|
||||
$trace['1']['line']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_result->addFailure($this, $message);
|
||||
$this->_failed = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes a test.
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
function pass() {
|
||||
if (!$this->_failed) {
|
||||
$this->_result->addPassedTest($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, open a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @abstract
|
||||
*/
|
||||
function setUp() { /* abstract */ }
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, close a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @abstract
|
||||
*/
|
||||
function tearDown() { /* abstract */ }
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* c-hanging-comment-ender-p: nil
|
||||
* End:
|
||||
*/
|
||||
?>
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* PHP Version 4
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Testing
|
||||
* @package PHPUnit
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: TestDecorator.php 2 2009-03-16 20:22:51Z ggiunta $
|
||||
* @link http://pear.php.net/package/PHPUnit
|
||||
* @since File available since Release 1.0.0
|
||||
*/
|
||||
|
||||
require_once 'PHPUnit/TestCase.php';
|
||||
require_once 'PHPUnit/TestSuite.php';
|
||||
|
||||
if (!function_exists('is_a')) {
|
||||
require_once 'PHP/Compat/Function/is_a.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* A Decorator for Tests.
|
||||
*
|
||||
* Use TestDecorator as the base class for defining new
|
||||
* test decorators. Test decorator subclasses can be introduced
|
||||
* to add behaviour before or after a test is run.
|
||||
*
|
||||
* @category Testing
|
||||
* @package PHPUnit
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/PHPUnit
|
||||
* @since Class available since Release 1.0.0
|
||||
*/
|
||||
class PHPUnit_TestDecorator {
|
||||
/**
|
||||
* The Test to be decorated.
|
||||
*
|
||||
* @var object
|
||||
* @access protected
|
||||
*/
|
||||
var $_test = NULL;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param object
|
||||
* @access public
|
||||
*/
|
||||
function PHPUnit_TestDecorator(&$test) {
|
||||
if (is_object($test) &&
|
||||
(is_a($test, 'PHPUnit_TestCase') ||
|
||||
is_a($test, 'PHPUnit_TestSuite'))) {
|
||||
|
||||
$this->_test = &$test;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the test and collects the
|
||||
* result in a TestResult.
|
||||
*
|
||||
* @param object
|
||||
* @access public
|
||||
*/
|
||||
function basicRun(&$result) {
|
||||
$this->_test->run($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of test cases that
|
||||
* will be run by this test.
|
||||
*
|
||||
* @return integer
|
||||
* @access public
|
||||
*/
|
||||
function countTestCases() {
|
||||
return $this->_test->countTestCases();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the test to be run.
|
||||
*
|
||||
* @return object
|
||||
* @access public
|
||||
*/
|
||||
function &getTest() {
|
||||
return $this->_test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the decorated test and collects the
|
||||
* result in a TestResult.
|
||||
*
|
||||
* @param object
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
function run(&$result) { /* abstract */ }
|
||||
|
||||
/**
|
||||
* Returns a string representation of the test.
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function toString() {
|
||||
return $this->_test->toString();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* c-hanging-comment-ender-p: nil
|
||||
* End:
|
||||
*/
|
||||
?>
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* PHP Version 4
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Testing
|
||||
* @package PHPUnit
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: TestFailure.php 2 2009-03-16 20:22:51Z ggiunta $
|
||||
* @link http://pear.php.net/package/PHPUnit
|
||||
* @since File available since Release 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* A TestFailure collects a failed test together with the caught exception.
|
||||
*
|
||||
* @category Testing
|
||||
* @package PHPUnit
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/PHPUnit
|
||||
* @since Class available since Release 1.0.0
|
||||
*/
|
||||
class PHPUnit_TestFailure {
|
||||
/**
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $_failedTest;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_thrownException;
|
||||
|
||||
/**
|
||||
* Constructs a TestFailure with the given test and exception.
|
||||
*
|
||||
* @param object
|
||||
* @param string
|
||||
* @access public
|
||||
*/
|
||||
function PHPUnit_TestFailure(&$failedTest, &$thrownException) {
|
||||
$this->_failedTest = &$failedTest;
|
||||
$this->_thrownException = &$thrownException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the failed test.
|
||||
*
|
||||
* @return object
|
||||
* @access public
|
||||
*/
|
||||
function &failedTest() {
|
||||
return $this->_failedTest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the thrown exception.
|
||||
*
|
||||
* @return object
|
||||
* @access public
|
||||
*/
|
||||
function &thrownException() {
|
||||
return $this->_thrownException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a short description of the failure.
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function toString() {
|
||||
return sprintf(
|
||||
"TestCase %s->%s() failed: %s\n",
|
||||
|
||||
get_class($this->_failedTest),
|
||||
$this->_failedTest->getName(),
|
||||
$this->_thrownException
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* c-hanging-comment-ender-p: nil
|
||||
* End:
|
||||
*/
|
||||
?>
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* PHP Version 4
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Testing
|
||||
* @package PHPUnit
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: TestListener.php 2 2009-03-16 20:22:51Z ggiunta $
|
||||
* @link http://pear.php.net/package/PHPUnit
|
||||
* @since File available since Release 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Listener for test progress.
|
||||
*
|
||||
* Here is an example:
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* require_once 'PHPUnit.php';
|
||||
* require_once 'PHPUnit/TestListener.php';
|
||||
*
|
||||
* class MathTest extends PHPUnit_TestCase {
|
||||
* var $fValue1;
|
||||
* var $fValue2;
|
||||
*
|
||||
* function MathTest($name) {
|
||||
* $this->PHPUnit_TestCase($name);
|
||||
* }
|
||||
*
|
||||
* function setUp() {
|
||||
* $this->fValue1 = 2;
|
||||
* $this->fValue2 = 3;
|
||||
* }
|
||||
*
|
||||
* function testAdd() {
|
||||
* $this->assertTrue($this->fValue1 + $this->fValue2 == 4);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* class MyListener extends PHPUnit_TestListener {
|
||||
* function addError(&$test, &$t) {
|
||||
* print "MyListener::addError() called.\n";
|
||||
* }
|
||||
*
|
||||
* function addFailure(&$test, &$t) {
|
||||
* print "MyListener::addFailure() called.\n";
|
||||
* }
|
||||
*
|
||||
* function endTest(&$test) {
|
||||
* print "MyListener::endTest() called.\n";
|
||||
* }
|
||||
*
|
||||
* function startTest(&$test) {
|
||||
* print "MyListener::startTest() called.\n";
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* $suite = new PHPUnit_TestSuite;
|
||||
* $suite->addTest(new MathTest('testAdd'));
|
||||
*
|
||||
* $result = new PHPUnit_TestResult;
|
||||
* $result->addListener(new MyListener);
|
||||
*
|
||||
* $suite->run($result);
|
||||
* print $result->toString();
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* @category Testing
|
||||
* @package PHPUnit
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/PHPUnit
|
||||
* @since Class available since Release 1.0.0
|
||||
*/
|
||||
class PHPUnit_TestListener {
|
||||
/**
|
||||
* An error occurred.
|
||||
*
|
||||
* @param object
|
||||
* @param object
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
function addError(&$test, &$t) { /*abstract */ }
|
||||
|
||||
/**
|
||||
* A failure occurred.
|
||||
*
|
||||
* @param object
|
||||
* @param object
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
function addFailure(&$test, &$t) { /*abstract */ }
|
||||
|
||||
/**
|
||||
* A test ended.
|
||||
*
|
||||
* @param object
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
function endTest(&$test) { /*abstract */ }
|
||||
|
||||
/**
|
||||
* A test started.
|
||||
*
|
||||
* @param object
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
function startTest(&$test) { /*abstract */ }
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* c-hanging-comment-ender-p: nil
|
||||
* End:
|
||||
*/
|
||||
?>
|
||||
@@ -0,0 +1,321 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* PHP Version 4
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Testing
|
||||
* @package PHPUnit
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: TestResult.php 2 2009-03-16 20:22:51Z ggiunta $
|
||||
* @link http://pear.php.net/package/PHPUnit
|
||||
* @since File available since Release 1.0.0
|
||||
*/
|
||||
|
||||
require_once 'PHPUnit/TestFailure.php';
|
||||
require_once 'PHPUnit/TestListener.php';
|
||||
|
||||
if (!function_exists('is_a')) {
|
||||
require_once 'PHP/Compat/Function/is_a.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* A TestResult collects the results of executing a test case.
|
||||
*
|
||||
* @category Testing
|
||||
* @package PHPUnit
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/PHPUnit
|
||||
* @since Class available since Release 1.0.0
|
||||
*/
|
||||
class PHPUnit_TestResult {
|
||||
/**
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $_errors = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $_failures = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $_listeners = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $_passedTests = array();
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
* @access protected
|
||||
*/
|
||||
var $_runTests = 0;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
var $_stop = FALSE;
|
||||
|
||||
/**
|
||||
* Adds an error to the list of errors.
|
||||
* The passed in exception caused the error.
|
||||
*
|
||||
* @param object
|
||||
* @param object
|
||||
* @access public
|
||||
*/
|
||||
function addError(&$test, &$t) {
|
||||
$this->_errors[] = new PHPUnit_TestFailure($test, $t);
|
||||
|
||||
for ($i = 0; $i < sizeof($this->_listeners); $i++) {
|
||||
$this->_listeners[$i]->addError($test, $t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a failure to the list of failures.
|
||||
* The passed in exception caused the failure.
|
||||
*
|
||||
* @param object
|
||||
* @param object
|
||||
* @access public
|
||||
*/
|
||||
function addFailure(&$test, &$t) {
|
||||
$this->_failures[] = new PHPUnit_TestFailure($test, $t);
|
||||
|
||||
for ($i = 0; $i < sizeof($this->_listeners); $i++) {
|
||||
$this->_listeners[$i]->addFailure($test, $t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a TestListener.
|
||||
*
|
||||
* @param object
|
||||
* @access public
|
||||
*/
|
||||
function addListener(&$listener) {
|
||||
if (is_object($listener) &&
|
||||
is_a($listener, 'PHPUnit_TestListener')) {
|
||||
$this->_listeners[] = &$listener;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a passed test to the list of passed tests.
|
||||
*
|
||||
* @param object
|
||||
* @access public
|
||||
*/
|
||||
function addPassedTest(&$test) {
|
||||
$this->_passedTests[] = &$test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Informs the result that a test was completed.
|
||||
*
|
||||
* @param object
|
||||
* @access public
|
||||
*/
|
||||
function endTest(&$test) {
|
||||
for ($i = 0; $i < sizeof($this->_listeners); $i++) {
|
||||
$this->_listeners[$i]->endTest($test);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of detected errors.
|
||||
*
|
||||
* @return integer
|
||||
* @access public
|
||||
*/
|
||||
function errorCount() {
|
||||
return sizeof($this->_errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Enumeration for the errors.
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
function &errors() {
|
||||
return $this->_errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of detected failures.
|
||||
*
|
||||
* @return integer
|
||||
* @access public
|
||||
*/
|
||||
function failureCount() {
|
||||
return sizeof($this->_failures);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Enumeration for the failures.
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
function &failures() {
|
||||
return $this->_failures;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Enumeration for the passed tests.
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
function &passedTests() {
|
||||
return $this->_passedTests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a TestListener.
|
||||
* This requires the Zend Engine 2 (to work properly).
|
||||
*
|
||||
* @param object
|
||||
* @access public
|
||||
*/
|
||||
function removeListener(&$listener) {
|
||||
for ($i = 0; $i < sizeof($this->_listeners); $i++) {
|
||||
if ($this->_listeners[$i] === $listener) {
|
||||
unset($this->_listeners[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a TestCase.
|
||||
*
|
||||
* @param object
|
||||
* @access public
|
||||
*/
|
||||
function run(&$test) {
|
||||
$this->startTest($test);
|
||||
$this->_runTests++;
|
||||
$test->runBare();
|
||||
$this->endTest($test);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of run tests.
|
||||
*
|
||||
* @return integer
|
||||
* @access public
|
||||
*/
|
||||
function runCount() {
|
||||
return $this->_runTests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the test run should stop.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function shouldStop() {
|
||||
return $this->_stop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Informs the result that a test will be started.
|
||||
*
|
||||
* @param object
|
||||
* @access public
|
||||
*/
|
||||
function startTest(&$test) {
|
||||
for ($i = 0; $i < sizeof($this->_listeners); $i++) {
|
||||
$this->_listeners[$i]->startTest($test);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks that the test run should stop.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function stop() {
|
||||
$this->_stop = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a HTML representation of the test result.
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function toHTML() {
|
||||
return '<pre>' . htmlspecialchars($this->toString()) . '</pre>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a text representation of the test result.
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function toString() {
|
||||
$result = '';
|
||||
|
||||
foreach ($this->_passedTests as $passedTest) {
|
||||
$result .= sprintf(
|
||||
"TestCase %s->%s() passed\n",
|
||||
|
||||
get_class($passedTest),
|
||||
$passedTest->getName()
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($this->_failures as $failedTest) {
|
||||
$result .= $failedTest->toString();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the entire test was successful or not.
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function wasSuccessful() {
|
||||
if (empty($this->_errors) && empty($this->_failures)) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* c-hanging-comment-ender-p: nil
|
||||
* End:
|
||||
*/
|
||||
?>
|
||||
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* PHP Version 4
|
||||
*
|
||||
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
||||
* that is available through the world-wide-web at the following URI:
|
||||
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
||||
* the PHP License and are unable to obtain it through the web, please
|
||||
* send a note to license@php.net so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Testing
|
||||
* @package PHPUnit
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id: TestSuite.php 2 2009-03-16 20:22:51Z ggiunta $
|
||||
* @link http://pear.php.net/package/PHPUnit
|
||||
* @since File available since Release 1.0.0
|
||||
*/
|
||||
|
||||
require_once 'PHPUnit/TestCase.php';
|
||||
|
||||
/**
|
||||
* A TestSuite is a Composite of Tests. It runs a collection of test cases.
|
||||
*
|
||||
* Here is an example using the dynamic test definition.
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* $suite = new PHPUnit_TestSuite();
|
||||
* $suite->addTest(new MathTest('testPass'));
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* Alternatively, a TestSuite can extract the tests to be run automatically.
|
||||
* To do so you pass the classname of your TestCase class to the TestSuite
|
||||
* constructor.
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* $suite = new TestSuite('classname');
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* This constructor creates a suite with all the methods starting with
|
||||
* "test" that take no arguments.
|
||||
*
|
||||
* @category Testing
|
||||
* @package PHPUnit
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/PHPUnit
|
||||
* @since Class available since Release 1.0.0
|
||||
*/
|
||||
class PHPUnit_TestSuite {
|
||||
/**
|
||||
* The name of the test suite.
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_name = '';
|
||||
|
||||
/**
|
||||
* The tests in the test suite.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_tests = array();
|
||||
|
||||
/**
|
||||
* Constructs a TestSuite.
|
||||
*
|
||||
* @param mixed
|
||||
* @access public
|
||||
*/
|
||||
function PHPUnit_TestSuite($test = FALSE) {
|
||||
if ($test !== FALSE) {
|
||||
$this->setName($test);
|
||||
$this->addTestSuite($test);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a test to the suite.
|
||||
*
|
||||
* @param object
|
||||
* @access public
|
||||
*/
|
||||
function addTest(&$test) {
|
||||
$this->_tests[] = &$test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the tests from the given class to the suite.
|
||||
*
|
||||
* @param string
|
||||
* @access public
|
||||
*/
|
||||
function addTestSuite($testClass) {
|
||||
if (class_exists($testClass)) {
|
||||
$methods = get_class_methods($testClass);
|
||||
$parentClasses = array(strtolower($testClass));
|
||||
$parentClass = $testClass;
|
||||
|
||||
while(is_string($parentClass = get_parent_class($parentClass))) {
|
||||
$parentClasses[] = $parentClass;
|
||||
}
|
||||
|
||||
foreach ($methods as $method) {
|
||||
if (substr($method, 0, 4) == 'test' &&
|
||||
!in_array($method, $parentClasses)) {
|
||||
$this->addTest(new $testClass($method));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of test cases that will be run by this test.
|
||||
*
|
||||
* @return integer
|
||||
* @access public
|
||||
*/
|
||||
function countTestCases() {
|
||||
$count = 0;
|
||||
|
||||
foreach ($this->_tests as $test) {
|
||||
$count += $test->countTestCases();
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the suite.
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function getName() {
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the tests and collects their result in a TestResult.
|
||||
*
|
||||
* @param object
|
||||
* @access public
|
||||
*/
|
||||
function run(&$result, $show_progress='') {
|
||||
for ($i = 0; $i < sizeof($this->_tests) && !$result->shouldStop(); $i++) {
|
||||
$this->_tests[$i]->run($result);
|
||||
if ($show_progress != '') {
|
||||
echo $show_progress; flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a test.
|
||||
*
|
||||
* @param object
|
||||
* @param object
|
||||
* @access public
|
||||
*/
|
||||
function runTest(&$test, &$result) {
|
||||
$test->run($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the suite.
|
||||
*
|
||||
* @param string
|
||||
* @access public
|
||||
*/
|
||||
function setName($name) {
|
||||
$this->_name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the test at the given index.
|
||||
*
|
||||
* @param integer
|
||||
* @return object
|
||||
* @access public
|
||||
*/
|
||||
function &testAt($index) {
|
||||
if (isset($this->_tests[$index])) {
|
||||
return $this->_tests[$index];
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of tests in this suite.
|
||||
*
|
||||
* @return integer
|
||||
* @access public
|
||||
*/
|
||||
function testCount() {
|
||||
return sizeof($this->_tests);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tests as an enumeration.
|
||||
*
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
function &tests() {
|
||||
return $this->_tests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the test suite.
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function toString() {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* c-hanging-comment-ender-p: nil
|
||||
* End:
|
||||
*/
|
||||
?>
|
||||
Reference in New Issue
Block a user