mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Updated XMLRPC to 3.0.0 beta
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 44 2009-08-04 21:33:50Z 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(); @ob_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:
|
||||
*/
|
||||
?>
|
||||
301
include/limesurvey/admin/classes/xmlrpc/test/benchmark.php
Normal file
301
include/limesurvey/admin/classes/xmlrpc/test/benchmark.php
Normal file
@@ -0,0 +1,301 @@
|
||||
<?php
|
||||
/**
|
||||
* Benchamrking suite for the PHP-XMLRPC lib
|
||||
* @author Gaetano Giunta
|
||||
* @version $Id: benchmark.php 52 2009-08-05 10:15:23Z ggiunta $
|
||||
* @copyright (c) 2005-2009 G. Giunta
|
||||
* @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
|
||||
*
|
||||
* @todo add a test for response ok in call testing?
|
||||
**/
|
||||
|
||||
include(getcwd().'/parse_args.php');
|
||||
|
||||
require_once('xmlrpc.inc');
|
||||
|
||||
// Set up PHP structures to be used in many tests
|
||||
$data1 = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00');
|
||||
$data2 = array('zero' => $data1, 'one' => $data1, 'two' => $data1, 'three' => $data1, 'four' => $data1, 'five' => $data1, 'six' => $data1, 'seven' => $data1, 'eight' => $data1, 'nine' => $data1);
|
||||
$data = array($data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2);
|
||||
$keys = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
|
||||
|
||||
$test_results=array();
|
||||
$xd = extension_loaded('xdebug') && ini_get('xdebug.profiler_enable');
|
||||
if ($xd)
|
||||
$num_tests = 1;
|
||||
else
|
||||
$num_tests = 10;
|
||||
|
||||
$title = 'XML-RPC Benchmark Tests';
|
||||
|
||||
if(isset($_SERVER['REQUEST_METHOD']))
|
||||
{
|
||||
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n<head>\n<title>$title</title>\n</head>\n<body>\n<h1>$title</h1>\n<pre>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "$title\n\n";
|
||||
}
|
||||
|
||||
if(isset($_SERVER['REQUEST_METHOD']))
|
||||
{
|
||||
echo "<h3>Using lib version: $xmlrpcVersion on PHP version: ".phpversion()."</h3>\n";
|
||||
if ($xd) echo "<h4>XDEBUG profiling enabled: skipping remote tests. Trace file is: ".htmlspecialchars(xdebug_get_profiler_filename())."</h4>\n";
|
||||
flush();
|
||||
ob_flush();
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Using lib version: $xmlrpcVersion on PHP version: ".phpversion()."\n";
|
||||
if ($xd) echo "XDEBUG profiling enabled: skipping remote tests\nTrace file is: ".xdebug_get_profiler_filename()."\n";
|
||||
}
|
||||
|
||||
// test 'old style' data encoding vs. 'automatic style' encoding
|
||||
begin_test('Data encoding (large array)', 'manual encoding');
|
||||
for ($i = 0; $i < $num_tests; $i++)
|
||||
{
|
||||
$vals = array();
|
||||
for ($j = 0; $j < 10; $j++)
|
||||
{
|
||||
$valarray = array();
|
||||
foreach ($data[$j] as $key => $val)
|
||||
{
|
||||
$values = array();
|
||||
$values[] = new xmlrpcval($val[0], 'int');
|
||||
$values[] = new xmlrpcval($val[1], 'double');
|
||||
$values[] = new xmlrpcval($val[2], 'string');
|
||||
$values[] = new xmlrpcval($val[3], 'boolean');
|
||||
$values[] = new xmlrpcval($val[4], 'dateTime.iso8601');
|
||||
$values[] = new xmlrpcval($val[5], 'int');
|
||||
$values[] = new xmlrpcval($val[6], 'double');
|
||||
$values[] = new xmlrpcval($val[7], 'string');
|
||||
$values[] = new xmlrpcval($val[8], 'boolean');
|
||||
$values[] = new xmlrpcval($val[9], 'dateTime.iso8601');
|
||||
$valarray[$key] = new xmlrpcval($values, 'array');
|
||||
}
|
||||
$vals[] = new xmlrpcval($valarray, 'struct');
|
||||
}
|
||||
$value = new xmlrpcval($vals, 'array');
|
||||
$out = $value->serialize();
|
||||
}
|
||||
end_test('Data encoding (large array)', 'manual encoding', $out);
|
||||
|
||||
begin_test('Data encoding (large array)', 'automatic encoding');
|
||||
for ($i = 0; $i < $num_tests; $i++)
|
||||
{
|
||||
$value = php_xmlrpc_encode($data, array('auto_dates'));
|
||||
$out = $value->serialize();
|
||||
}
|
||||
end_test('Data encoding (large array)', 'automatic encoding', $out);
|
||||
|
||||
if (function_exists('xmlrpc_set_type'))
|
||||
{
|
||||
begin_test('Data encoding (large array)', 'xmlrpc-epi encoding');
|
||||
for ($i = 0; $i < $num_tests; $i++)
|
||||
{
|
||||
for ($j = 0; $j < 10; $j++)
|
||||
foreach ($keys as $k)
|
||||
{
|
||||
xmlrpc_set_type($data[$j][$k][4], 'datetime');
|
||||
xmlrpc_set_type($data[$j][$k][8], 'datetime');
|
||||
}
|
||||
$out = xmlrpc_encode($data);
|
||||
}
|
||||
end_test('Data encoding (large array)', 'xmlrpc-epi encoding', $out);
|
||||
}
|
||||
|
||||
// test 'old style' data decoding vs. 'automatic style' decoding
|
||||
$dummy = new xmlrpcmsg('');
|
||||
$out = new xmlrpcresp($value);
|
||||
$in = '<?xml version="1.0" ?>'."\n".$out->serialize();
|
||||
|
||||
begin_test('Data decoding (large array)', 'manual decoding');
|
||||
for ($i = 0; $i < $num_tests; $i++)
|
||||
{
|
||||
$response =& $dummy->ParseResponse($in, true);
|
||||
$value = $response->value();
|
||||
$result = array();
|
||||
for ($k = 0; $k < $value->arraysize(); $k++)
|
||||
{
|
||||
$val1 = $value->arraymem($k);
|
||||
$out = array();
|
||||
while (list($name, $val) = $val1->structeach())
|
||||
{
|
||||
$out[$name] = array();
|
||||
for ($j = 0; $j < $val->arraysize(); $j++)
|
||||
{
|
||||
$data = $val->arraymem($j);
|
||||
$out[$name][] = $data->scalarval();
|
||||
}
|
||||
} // while
|
||||
$result[] = $out;
|
||||
}
|
||||
}
|
||||
end_test('Data decoding (large array)', 'manual decoding', $result);
|
||||
|
||||
begin_test('Data decoding (large array)', 'automatic decoding');
|
||||
for ($i = 0; $i < $num_tests; $i++)
|
||||
{
|
||||
$response =& $dummy->ParseResponse($in, true, 'phpvals');
|
||||
$value = $response->value();
|
||||
}
|
||||
end_test('Data decoding (large array)', 'automatic decoding', $value);
|
||||
|
||||
if (function_exists('xmlrpc_decode'))
|
||||
{
|
||||
begin_test('Data decoding (large array)', 'xmlrpc-epi decoding');
|
||||
for ($i = 0; $i < $num_tests; $i++)
|
||||
{
|
||||
$response =& $dummy->ParseResponse($in, true, 'xml');
|
||||
$value = xmlrpc_decode($response->value());
|
||||
}
|
||||
end_test('Data decoding (large array)', 'xmlrpc-epi decoding', $value);
|
||||
}
|
||||
|
||||
if (!$xd) {
|
||||
|
||||
/// test multicall vs. many calls vs. keep-alives
|
||||
$value = php_xmlrpc_encode($data1, array('auto_dates'));
|
||||
$msg = new xmlrpcmsg('interopEchoTests.echoValue', array($value));
|
||||
$msgs=array();
|
||||
for ($i = 0; $i < 25; $i++)
|
||||
$msgs[] = $msg;
|
||||
$server = explode(':', $LOCALSERVER);
|
||||
if(count($server) > 1)
|
||||
{
|
||||
$c = new xmlrpc_client($URI, $server[0], $server[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$c = new xmlrpc_client($URI, $LOCALSERVER);
|
||||
}
|
||||
// do not interfere with http compression
|
||||
$c->accepted_compression = array();
|
||||
//$c->debug=true;
|
||||
|
||||
if (function_exists('gzinflate')) {
|
||||
$c->accepted_compression = null;
|
||||
}
|
||||
begin_test('Repeated send (small array)', 'http 10');
|
||||
$response = array();
|
||||
for ($i = 0; $i < 25; $i++)
|
||||
{
|
||||
$resp =& $c->send($msg);
|
||||
$response[] = $resp->value();
|
||||
}
|
||||
end_test('Repeated send (small array)', 'http 10', $response);
|
||||
|
||||
if (function_exists('curl_init'))
|
||||
{
|
||||
begin_test('Repeated send (small array)', 'http 11 w. keep-alive');
|
||||
$response = array();
|
||||
for ($i = 0; $i < 25; $i++)
|
||||
{
|
||||
$resp =& $c->send($msg, 10, 'http11');
|
||||
$response[] = $resp->value();
|
||||
}
|
||||
end_test('Repeated send (small array)', 'http 11 w. keep-alive', $response);
|
||||
|
||||
$c->keepalive = false;
|
||||
begin_test('Repeated send (small array)', 'http 11');
|
||||
$response = array();
|
||||
for ($i = 0; $i < 25; $i++)
|
||||
{
|
||||
$resp =& $c->send($msg, 10, 'http11');
|
||||
$response[] = $resp->value();
|
||||
}
|
||||
end_test('Repeated send (small array)', 'http 11', $response);
|
||||
}
|
||||
|
||||
begin_test('Repeated send (small array)', 'multicall');
|
||||
$response =& $c->send($msgs);
|
||||
foreach ($response as $key =>& $val)
|
||||
{
|
||||
$val = $val->value();
|
||||
}
|
||||
end_test('Repeated send (small array)', 'multicall', $response);
|
||||
|
||||
if (function_exists('gzinflate'))
|
||||
{
|
||||
$c->accepted_compression = array('gzip');
|
||||
$c->request_compression = 'gzip';
|
||||
|
||||
begin_test('Repeated send (small array)', 'http 10 w. compression');
|
||||
$response = array();
|
||||
for ($i = 0; $i < 25; $i++)
|
||||
{
|
||||
$resp =& $c->send($msg);
|
||||
$response[] = $resp->value();
|
||||
}
|
||||
end_test('Repeated send (small array)', 'http 10 w. compression', $response);
|
||||
|
||||
if (function_exists('curl_init'))
|
||||
{
|
||||
begin_test('Repeated send (small array)', 'http 11 w. keep-alive and compression');
|
||||
$response = array();
|
||||
for ($i = 0; $i < 25; $i++)
|
||||
{
|
||||
$resp =& $c->send($msg, 10, 'http11');
|
||||
$response[] = $resp->value();
|
||||
}
|
||||
end_test('Repeated send (small array)', 'http 11 w. keep-alive and compression', $response);
|
||||
|
||||
$c->keepalive = false;
|
||||
begin_test('Repeated send (small array)', 'http 11 w. compression');
|
||||
$response = array();
|
||||
for ($i = 0; $i < 25; $i++)
|
||||
{
|
||||
$resp =& $c->send($msg, 10, 'http11');
|
||||
$response[] = $resp->value();
|
||||
}
|
||||
end_test('Repeated send (small array)', 'http 11 w. compression', $response);
|
||||
}
|
||||
|
||||
begin_test('Repeated send (small array)', 'multicall w. compression');
|
||||
$response =& $c->send($msgs);
|
||||
foreach ($response as $key =>& $val)
|
||||
{
|
||||
$val = $val->value();
|
||||
}
|
||||
end_test('Repeated send (small array)', 'multicall w. compression', $response);
|
||||
}
|
||||
|
||||
} // end of 'if no xdebug profiling'
|
||||
|
||||
function begin_test($test_name, $test_case)
|
||||
{
|
||||
global $test_results;
|
||||
if (!isset($test_results[$test_name]))
|
||||
$test_results[$test_name]=array();
|
||||
$test_results[$test_name][$test_case] = array();
|
||||
$test_results[$test_name][$test_case]['time'] = microtime(true);
|
||||
}
|
||||
|
||||
function end_test($test_name, $test_case, $test_result)
|
||||
{
|
||||
global $test_results;
|
||||
$end = microtime(true);
|
||||
if (!isset($test_results[$test_name][$test_case]))
|
||||
trigger_error('ending test that was not sterted');
|
||||
$test_results[$test_name][$test_case]['time'] = $end - $test_results[$test_name][$test_case]['time'];
|
||||
$test_results[$test_name][$test_case]['result'] = $test_result;
|
||||
echo '.';
|
||||
flush();
|
||||
ob_flush();
|
||||
}
|
||||
|
||||
|
||||
echo "\n";
|
||||
foreach($test_results as $test => $results)
|
||||
{
|
||||
echo "\nTEST: $test\n";
|
||||
foreach ($results as $case => $data)
|
||||
echo " $case: {$data['time']} secs - Output data CRC: ".crc32(serialize($data['result']))."\n";
|
||||
}
|
||||
|
||||
|
||||
if(isset($_SERVER['REQUEST_METHOD']))
|
||||
{
|
||||
echo "\n</pre>\n</body>\n</html>\n";
|
||||
}
|
||||
?>
|
||||
132
include/limesurvey/admin/classes/xmlrpc/test/parse_args.php
Normal file
132
include/limesurvey/admin/classes/xmlrpc/test/parse_args.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
* Common parameter parsing for benchmarks and tests scripts
|
||||
*
|
||||
* @param integer DEBUG
|
||||
* @param string LOCALSERVER
|
||||
* @param string URI
|
||||
* @param string HTTPSSERVER
|
||||
* @param string HTTPSSURI
|
||||
* @param string PROXY
|
||||
*
|
||||
* @version $Id: parse_args.php 37 2009-07-31 23:35:33Z ggiunta $
|
||||
* @copyright (C) 2007-2009 G. Giunta
|
||||
* @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
|
||||
**/
|
||||
|
||||
require_once('xmlrpc.inc');
|
||||
require_once('xmlrpcs.inc');
|
||||
|
||||
// play nice to older PHP versions that miss superglobals
|
||||
if(!isset($_SERVER))
|
||||
{
|
||||
$_SERVER = $HTTP_SERVER_VARS;
|
||||
$_GET = isset($HTTP_GET_VARS) ? $HTTP_GET_VARS : array();
|
||||
$_POST = isset($HTTP_POST_VARS) ? $HTTP_POST_VARS : array();
|
||||
}
|
||||
|
||||
// check for command line vs web page input params
|
||||
if(!isset($_SERVER['REQUEST_METHOD']))
|
||||
{
|
||||
if(isset($argv))
|
||||
{
|
||||
foreach($argv as $param)
|
||||
{
|
||||
$param = explode('=', $param);
|
||||
if(count($param) > 1)
|
||||
{
|
||||
$$param[0]=$param[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif(!ini_get('register_globals'))
|
||||
{
|
||||
// play nice to 'safe' PHP installations with register globals OFF
|
||||
// NB: we might as well consider using $_GET stuff later on...
|
||||
extract($_GET);
|
||||
extract($_POST);
|
||||
}
|
||||
|
||||
if(!isset($DEBUG))
|
||||
{
|
||||
$DEBUG = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$DEBUG = intval($DEBUG);
|
||||
}
|
||||
|
||||
if(!isset($LOCALSERVER))
|
||||
{
|
||||
if(isset($HTTP_HOST))
|
||||
{
|
||||
$LOCALSERVER = $HTTP_HOST;
|
||||
}
|
||||
elseif(isset($_SERVER['HTTP_HOST']))
|
||||
{
|
||||
$LOCALSERVER = $_SERVER['HTTP_HOST'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$LOCALSERVER = 'localhost';
|
||||
}
|
||||
}
|
||||
if(!isset($HTTPSSERVER))
|
||||
{
|
||||
$HTTPSSERVER = 'xmlrpc.usefulinc.com';
|
||||
}
|
||||
if(!isset($HTTPSURI))
|
||||
{
|
||||
$HTTPSURI = '/server.php';
|
||||
}
|
||||
if(!isset($PROXY))
|
||||
{
|
||||
$PROXYSERVER = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$arr = explode(':',$PROXY);
|
||||
$PROXYSERVER = $arr[0];
|
||||
if(count($arr) > 1)
|
||||
{
|
||||
$PROXYPORT = $arr[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$PROXYPORT = 8080;
|
||||
}
|
||||
}
|
||||
if(!isset($URI))
|
||||
{
|
||||
// GUESTIMATE the url of local demo server
|
||||
// play nice to php 3 and 4-5 in retrieving URL of server.php
|
||||
/// @todo filter out query string from REQUEST_URI
|
||||
if(isset($REQUEST_URI))
|
||||
{
|
||||
$URI = str_replace('/test/testsuite.php', '/demo/server/server.php', $REQUEST_URI);
|
||||
$URI = str_replace('/testsuite.php', '/server.php', $URI);
|
||||
$URI = str_replace('/test/benchmark.php', '/demo/server/server.php', $URI);
|
||||
$URI = str_replace('/benchmark.php', '/server.php', $URI);
|
||||
}
|
||||
elseif(isset($_SERVER['PHP_SELF']) && isset($_SERVER['REQUEST_METHOD']))
|
||||
{
|
||||
$URI = str_replace('/test/testsuite.php', '/demo/server/server.php', $_SERVER['PHP_SELF']);
|
||||
$URI = str_replace('/testsuite.php', '/server.php', $URI);
|
||||
$URI = str_replace('/test/benchmark.php', '/demo/server/server.php', $URI);
|
||||
$URI = str_replace('/benchmark.php', '/server.php', $URI);
|
||||
}
|
||||
else
|
||||
{
|
||||
$URI = '/demo/server/server.php';
|
||||
}
|
||||
}
|
||||
if($URI[0] != '/')
|
||||
{
|
||||
$URI = '/'.$URI;
|
||||
}
|
||||
if(!isset($LOCALPATH))
|
||||
{
|
||||
$LOCALPATH = dirname(__FILE__);
|
||||
}
|
||||
?>
|
||||
106
include/limesurvey/admin/classes/xmlrpc/test/phpunit.php
Normal file
106
include/limesurvey/admin/classes/xmlrpc/test/phpunit.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?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: phpunit.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/TestResult.php';
|
||||
require_once 'PHPUnit/TestSuite.php';
|
||||
|
||||
/**
|
||||
* PHPUnit runs a TestSuite and returns a TestResult object.
|
||||
*
|
||||
* Here is an example:
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* require_once 'PHPUnit.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 == 5);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* $suite = new PHPUnit_TestSuite();
|
||||
* $suite->addTest(new MathTest('testAdd'));
|
||||
*
|
||||
* $result = PHPUnit::run($suite);
|
||||
* print $result->toHTML();
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* Alternatively, you can pass a class name to the PHPUnit_TestSuite()
|
||||
* constructor and let it automatically add all methods of that class
|
||||
* that start with 'test' to the suite:
|
||||
*
|
||||
* <code>
|
||||
* <?php
|
||||
* $suite = new PHPUnit_TestSuite('MathTest');
|
||||
* $result = PHPUnit::run($suite);
|
||||
* print $result->toHTML();
|
||||
* ?>
|
||||
* </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 {
|
||||
/**
|
||||
* Runs a test(suite).
|
||||
*
|
||||
* @param mixed
|
||||
* @return PHPUnit_TestResult
|
||||
* @access public
|
||||
*/
|
||||
function &run(&$suite, $show_progress=false) {
|
||||
$result = new PHPUnit_TestResult();
|
||||
$suite->run($result, $show_progress);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* c-hanging-comment-ender-p: nil
|
||||
* End:
|
||||
*/
|
||||
?>
|
||||
1519
include/limesurvey/admin/classes/xmlrpc/test/testsuite.php
Normal file
1519
include/limesurvey/admin/classes/xmlrpc/test/testsuite.php
Normal file
File diff suppressed because it is too large
Load Diff
183
include/limesurvey/admin/classes/xmlrpc/test/verify_compat.php
Normal file
183
include/limesurvey/admin/classes/xmlrpc/test/verify_compat.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
/**
|
||||
* Verify compatibility level of current php install with php-xmlrpc lib
|
||||
*
|
||||
* @version $Id: verify_compat.php 38 2009-07-31 23:36:31Z ggiunta $
|
||||
* @author Gaetano Giunta
|
||||
* @copyright (C) 2006-2009 G. Giunta
|
||||
* @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
|
||||
*
|
||||
* @todo add a test for php output buffering?
|
||||
*/
|
||||
|
||||
function phpxmlrpc_verify_compat($mode='client')
|
||||
{
|
||||
$tests = array();
|
||||
|
||||
if ($mode == 'server')
|
||||
{
|
||||
// test for php version
|
||||
$ver = phpversion();
|
||||
$tests['php_version'] = array();
|
||||
$tests['php_version']['description'] = 'PHP version found: '.$ver.".\n\n";
|
||||
if (version_compare($ver, '5') < 0)
|
||||
{
|
||||
$tests['php_version']['status'] = 0;
|
||||
$tests['php_version']['description'] .= 'This version of PHP is not compatible with this release of the PHP XMLRPC library. Please upgrade to php 5 or later';
|
||||
}
|
||||
else if (version_compare($ver, '5.0.3') < 0)
|
||||
{
|
||||
$tests['php_version']['status'] = 1;
|
||||
$tests['php_version']['description'] .= "This version of PHP is almost completely compatible with the PHP XMLRPC library.\nThe only unavailable function is automatic mapping of php functions to xmlrpc methods";
|
||||
}
|
||||
else
|
||||
{
|
||||
$tests['php_version']['status'] = 2;
|
||||
$tests['php_version']['description'] .= 'This version of PHP is fully compatible with the PHP XMLRPC library';
|
||||
}
|
||||
|
||||
// test for zlib
|
||||
$tests['zlib'] = array();
|
||||
if (!function_exists('gzinflate'))
|
||||
{
|
||||
$tests['zlib']['status'] = 0;
|
||||
$tests['zlib']['description'] = "The zlib extension is not enabled.\n\nYou will not be able to receive compressed requests or send compressed responses, unless using the cURL library (for 'HTTPS' and 'HTTP 1.1' connections)";
|
||||
}
|
||||
else
|
||||
{
|
||||
$tests['zlib']['status'] = 2;
|
||||
$tests['zlib']['description'] = "The zlib extension is enabled.\n\nYou will be able to receive compressed requests and send compressed responses for the 'HTTP' protocol";
|
||||
}
|
||||
|
||||
// test for dispaly of php errors in xml reponse
|
||||
if (ini_get('display_errors'))
|
||||
{
|
||||
if (intval(ini_get('error_reporting')) && E_NOTICE )
|
||||
{
|
||||
$tests['display_errors']['status'] = 1;
|
||||
$tests['display_errors']['description'] = "Error reporting level includes E_NOTICE errors, and display_errors is set to ON.\n\nAny error, warning or notice raised while executing php code exposed as xmlrpc method will result in an invalid xmlrpc response";
|
||||
}
|
||||
else
|
||||
{
|
||||
$tests['display_errors']['status'] = 1;
|
||||
$tests['display_errors']['description'] = "display_errors is set to ON.\n\nAny error raised while executing php code exposed as xmlrpc method will result in an invalid xmlrpc response";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// test for php version
|
||||
$ver = phpversion();
|
||||
$tests['php_version'] = array();
|
||||
$tests['php_version']['description'] = 'PHP version found: '.$ver.".\n\n";
|
||||
if (version_compare($ver, '5') < 0)
|
||||
{
|
||||
$tests['php_version']['status'] = 0;
|
||||
$tests['php_version']['description'] .= 'This version of PHP is not compatible with the PHP XMLRPC library. Please upgrade to 5.0 or later';
|
||||
}
|
||||
else
|
||||
{
|
||||
$tests['php_version']['status'] = 2;
|
||||
$tests['php_version']['description'] .= 'This version of PHP is fully compatible with the PHP XMLRPC library';
|
||||
}
|
||||
|
||||
// test for zlib
|
||||
$tests['zlib'] = array();
|
||||
if (!function_exists('gzinflate'))
|
||||
{
|
||||
$tests['zlib']['status'] = 0;
|
||||
$tests['zlib']['description'] = "The zlib extension is not enabled.\n\nYou will not be able to send compressed requests or receive compressed responses, unless using the cURL library (for 'HTTPS' and 'HTTP 1.1' connections)";
|
||||
}
|
||||
else
|
||||
{
|
||||
$tests['zlib']['status'] = 2;
|
||||
$tests['zlib']['description'] = "The zlib extension is enabled.\n\nYou will be able to send compressed requests and receive compressed responses for the 'HTTP' protocol";
|
||||
}
|
||||
|
||||
// test for CURL
|
||||
$tests['curl'] = array();
|
||||
if (!extension_loaded('curl'))
|
||||
{
|
||||
$tests['curl']['status'] = 0;
|
||||
$tests['curl']['description'] = "The cURL extension is not enabled.\n\nYou will not be able to send and receive messages using 'HTTPS' and 'HTTP 1.1' protocols";
|
||||
}
|
||||
else
|
||||
{
|
||||
$info = curl_version();
|
||||
$tests['curl']['status'] = 2;
|
||||
$tests['curl']['description'] = "The cURL extension is enabled.\n\nYou will be able to send and receive messages using 'HTTPS' and 'HTTP 1.1' protocols";
|
||||
if (version_compare($ver, '4.3.8') < 0)
|
||||
{
|
||||
$tests['curl']['status'] = 1;
|
||||
$tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support keep-alives";
|
||||
}
|
||||
if (!((is_string($info) && strpos($info, 'zlib') !== null) || isset($info['libz_version'])))
|
||||
{
|
||||
$tests['curl']['status'] = 1;
|
||||
$tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support compressed messages";
|
||||
}
|
||||
if (!((is_string($info) && strpos($info, 'OpenSSL') !== null) || isset($info['ssl_version'])))
|
||||
{
|
||||
$tests['curl']['status'] = 1;
|
||||
$tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support HTTPS connections";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $tests;
|
||||
}
|
||||
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<title>PHP XMLRPC compatibility assessment</title>
|
||||
<style type="text/css">
|
||||
body, html {background-color: white; font-family: Arial, Verdana, Geneva, sans-serif; font-size: small; }
|
||||
table { border: 1px solid gray; padding: 0;}
|
||||
thead { background-color: silver; color: black; }
|
||||
td { margin: 0; padding: 0.5em; }
|
||||
tbody td { border-top: 1px solid gray; }
|
||||
.res0 { background-color: red; color: black; border-right: 1px solid gray; }
|
||||
.res1 { background-color: yellow; color: black; border-right: 1px solid gray; }
|
||||
.res2 { background-color: green; color: black; border-right: 1px solid gray; }
|
||||
.result { white-space: pre; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>PHPXMLRPC compatibility assessment with the current PHP install</h1>
|
||||
<h4>For phpxmlrpc version 3.0 or later</h4>
|
||||
<h3>Server usage</h3>
|
||||
<table cellspacing="0">
|
||||
<thead>
|
||||
<tr><td>Test</td><td>Result</td></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$res = phpxmlrpc_verify_compat('server');
|
||||
foreach($res as $test => $result)
|
||||
{
|
||||
echo '<tr><td class="res'.$result['status'].'">'.htmlspecialchars($test).'</td><td class="result">'.htmlspecialchars($result['description'])."</td></tr>\n";
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<h3>Client usage</h3>
|
||||
<table cellspacing="0">
|
||||
<thead>
|
||||
<tr><td>Test</td><td>Result</td></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$res = phpxmlrpc_verify_compat('client');
|
||||
foreach($res as $test => $result)
|
||||
{
|
||||
echo '<tr><td class="res'.$result['status'].'">'.htmlspecialchars($test).'</td><td class="result">'.htmlspecialchars($result['description'])."</td></tr>\n";
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user