forked from Cavemanon/cavepaintings
store enabled exts in a config file, rather than moving directories around
This commit is contained in:
196
lib/simpletest/extensions/pear_test_case.php
Executable file
196
lib/simpletest/extensions/pear_test_case.php
Executable file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
/**
|
||||
* adapter for SimpleTest to use PEAR PHPUnit test cases
|
||||
* @package SimpleTest
|
||||
* @subpackage Extensions
|
||||
* @version $Id: pear_test_case.php 1836 2008-12-21 00:02:26Z edwardzyang $
|
||||
*/
|
||||
|
||||
/**#@+
|
||||
* include SimpleTest files
|
||||
*/
|
||||
require_once(dirname(__FILE__) . '/../dumper.php');
|
||||
require_once(dirname(__FILE__) . '/../compatibility.php');
|
||||
require_once(dirname(__FILE__) . '/../test_case.php');
|
||||
require_once(dirname(__FILE__) . '/../expectation.php');
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Adapter for PEAR PHPUnit test case to allow
|
||||
* legacy PEAR test cases to be used with SimpleTest.
|
||||
* @package SimpleTest
|
||||
* @subpackage Extensions
|
||||
*/
|
||||
class PHPUnit_TestCase extends SimpleTestCase {
|
||||
private $_loosely_typed;
|
||||
|
||||
/**
|
||||
* Constructor. Sets the test name.
|
||||
* @param $label Test name to display.
|
||||
* @public
|
||||
*/
|
||||
function __construct($label = false) {
|
||||
parent::__construct($label);
|
||||
$this->_loosely_typed = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will test straight equality if set to loose
|
||||
* typing, or identity if not.
|
||||
* @param $first First value.
|
||||
* @param $second Comparison value.
|
||||
* @param $message Message to display.
|
||||
* @public
|
||||
*/
|
||||
function assertEquals($first, $second, $message = "%s", $delta = 0) {
|
||||
if ($this->_loosely_typed) {
|
||||
$expectation = new EqualExpectation($first);
|
||||
} else {
|
||||
$expectation = new IdenticalExpectation($first);
|
||||
}
|
||||
$this->assert($expectation, $second, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes if the value tested is not null.
|
||||
* @param $value Value to test against.
|
||||
* @param $message Message to display.
|
||||
* @public
|
||||
*/
|
||||
function assertNotNull($value, $message = "%s") {
|
||||
parent::assert(new TrueExpectation(), isset($value), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes if the value tested is null.
|
||||
* @param $value Value to test against.
|
||||
* @param $message Message to display.
|
||||
* @public
|
||||
*/
|
||||
function assertNull($value, $message = "%s") {
|
||||
parent::assert(new TrueExpectation(), !isset($value), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Identity test tests for the same object.
|
||||
* @param $first First object handle.
|
||||
* @param $second Hopefully the same handle.
|
||||
* @param $message Message to display.
|
||||
* @public
|
||||
*/
|
||||
function assertSame($first, $second, $message = "%s") {
|
||||
$dumper = new SimpleDumper();
|
||||
$message = sprintf(
|
||||
$message,
|
||||
"[" . $dumper->describeValue($first) .
|
||||
"] and [" . $dumper->describeValue($second) .
|
||||
"] should reference the same object");
|
||||
return $this->assert(
|
||||
new TrueExpectation(),
|
||||
SimpleTestCompatibility::isReference($first, $second),
|
||||
$message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inverted identity test.
|
||||
* @param $first First object handle.
|
||||
* @param $second Hopefully a different handle.
|
||||
* @param $message Message to display.
|
||||
* @public
|
||||
*/
|
||||
function assertNotSame($first, $second, $message = "%s") {
|
||||
$dumper = new SimpleDumper();
|
||||
$message = sprintf(
|
||||
$message,
|
||||
"[" . $dumper->describeValue($first) .
|
||||
"] and [" . $dumper->describeValue($second) .
|
||||
"] should not be the same object");
|
||||
return $this->assert(
|
||||
new falseExpectation(),
|
||||
SimpleTestCompatibility::isReference($first, $second),
|
||||
$message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends pass if the test condition resolves true,
|
||||
* a fail otherwise.
|
||||
* @param $condition Condition to test true.
|
||||
* @param $message Message to display.
|
||||
* @public
|
||||
*/
|
||||
function assertTrue($condition, $message = "%s") {
|
||||
parent::assert(new TrueExpectation(), $condition, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends pass if the test condition resolves false,
|
||||
* a fail otherwise.
|
||||
* @param $condition Condition to test false.
|
||||
* @param $message Message to display.
|
||||
* @public
|
||||
*/
|
||||
function assertFalse($condition, $message = "%s") {
|
||||
parent::assert(new FalseExpectation(), $condition, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a regex match. Needs refactoring.
|
||||
* @param $pattern Regex to match.
|
||||
* @param $subject String to search in.
|
||||
* @param $message Message to display.
|
||||
* @public
|
||||
*/
|
||||
function assertRegExp($pattern, $subject, $message = "%s") {
|
||||
$this->assert(new PatternExpectation($pattern), $subject, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the type of a value.
|
||||
* @param $value Value to take type of.
|
||||
* @param $type Hoped for type.
|
||||
* @param $message Message to display.
|
||||
* @public
|
||||
*/
|
||||
function assertType($value, $type, $message = "%s") {
|
||||
parent::assert(new TrueExpectation(), gettype($value) == strtolower($type), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets equality operation to act as a simple equal
|
||||
* comparison only, allowing a broader range of
|
||||
* matches.
|
||||
* @param $loosely_typed True for broader comparison.
|
||||
* @public
|
||||
*/
|
||||
function setLooselyTyped($loosely_typed) {
|
||||
$this->_loosely_typed = $loosely_typed;
|
||||
}
|
||||
|
||||
/**
|
||||
* For progress indication during
|
||||
* a test amongst other things.
|
||||
* @return Usually one.
|
||||
* @public
|
||||
*/
|
||||
function countTestCases() {
|
||||
return $this->getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for name, normally just the class
|
||||
* name.
|
||||
* @public
|
||||
*/
|
||||
function getName() {
|
||||
return $this->getLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing. For compatibility only.
|
||||
* @param $name Dummy
|
||||
* @public
|
||||
*/
|
||||
function setName($name) {
|
||||
}
|
||||
}
|
||||
?>
|
53
lib/simpletest/extensions/testdox.php
Executable file
53
lib/simpletest/extensions/testdox.php
Executable file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Extension for a TestDox reporter
|
||||
* @package SimpleTest
|
||||
* @subpackage Extensions
|
||||
* @version $Id: testdox.php 2004 2010-10-31 13:44:14Z jsweat $
|
||||
*/
|
||||
|
||||
/**
|
||||
* TestDox reporter
|
||||
* @package SimpleTest
|
||||
* @subpackage Extensions
|
||||
*/
|
||||
class TestDoxReporter extends SimpleReporter
|
||||
{
|
||||
var $_test_case_pattern = '/^TestOf(.*)$/';
|
||||
|
||||
function __construct($test_case_pattern = '/^TestOf(.*)$/') {
|
||||
parent::__construct();
|
||||
$this->_test_case_pattern = empty($test_case_pattern) ? '/^(.*)$/' : $test_case_pattern;
|
||||
}
|
||||
|
||||
function paintCaseStart($test_name) {
|
||||
preg_match($this->_test_case_pattern, $test_name, $matches);
|
||||
if (!empty($matches[1])) {
|
||||
echo $matches[1] . "\n";
|
||||
} else {
|
||||
echo $test_name . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
function paintCaseEnd($test_name) {
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
function paintMethodStart($test_name) {
|
||||
if (!preg_match('/^test(.*)$/i', $test_name, $matches)) {
|
||||
return;
|
||||
}
|
||||
$test_name = $matches[1];
|
||||
$test_name = preg_replace('/([A-Z])([A-Z])/', '$1 $2', $test_name);
|
||||
echo '- ' . strtolower(preg_replace('/([a-zA-Z])([A-Z0-9])/', '$1 $2', $test_name));
|
||||
}
|
||||
|
||||
function paintMethodEnd($test_name) {
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
function paintFail($message) {
|
||||
echo " [FAILED]";
|
||||
}
|
||||
}
|
||||
?>
|
107
lib/simpletest/extensions/testdox/test.php
Executable file
107
lib/simpletest/extensions/testdox/test.php
Executable file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
// $Id: test.php 1748 2008-04-14 01:50:41Z lastcraft $
|
||||
require_once dirname(__FILE__) . '/../../autorun.php';
|
||||
require_once dirname(__FILE__) . '/../testdox.php';
|
||||
|
||||
// uncomment to see test dox in action
|
||||
//SimpleTest::prefer(new TestDoxReporter());
|
||||
|
||||
class TestOfTestDoxReporter extends UnitTestCase
|
||||
{
|
||||
function testIsAnInstanceOfSimpleScorerAndReporter() {
|
||||
$dox = new TestDoxReporter();
|
||||
$this->assertIsA($dox, 'SimpleScorer');
|
||||
$this->assertIsA($dox, 'SimpleReporter');
|
||||
}
|
||||
|
||||
function testOutputsNameOfTestCase() {
|
||||
$dox = new TestDoxReporter();
|
||||
ob_start();
|
||||
$dox->paintCaseStart('TestOfTestDoxReporter');
|
||||
$buffer = ob_get_clean();
|
||||
$this->assertPattern('/^TestDoxReporter/', $buffer);
|
||||
}
|
||||
|
||||
function testOutputOfTestCaseNameFilteredByConstructParameter() {
|
||||
$dox = new TestDoxReporter('/^(.*)Test$/');
|
||||
ob_start();
|
||||
$dox->paintCaseStart('SomeGreatWidgetTest');
|
||||
$buffer = ob_get_clean();
|
||||
$this->assertPattern('/^SomeGreatWidget/', $buffer);
|
||||
}
|
||||
|
||||
function testIfTest_case_patternIsEmptyAssumeEverythingMatches() {
|
||||
$dox = new TestDoxReporter('');
|
||||
ob_start();
|
||||
$dox->paintCaseStart('TestOfTestDoxReporter');
|
||||
$buffer = ob_get_clean();
|
||||
$this->assertPattern('/^TestOfTestDoxReporter/', $buffer);
|
||||
}
|
||||
|
||||
function testEmptyLineInsertedWhenCaseEnds() {
|
||||
$dox = new TestDoxReporter();
|
||||
ob_start();
|
||||
$dox->paintCaseEnd('TestOfTestDoxReporter');
|
||||
$buffer = ob_get_clean();
|
||||
$this->assertEqual("\n", $buffer);
|
||||
}
|
||||
|
||||
function testPaintsTestMethodInTestDoxFormat() {
|
||||
$dox = new TestDoxReporter();
|
||||
ob_start();
|
||||
$dox->paintMethodStart('testSomeGreatTestCase');
|
||||
$buffer = ob_get_clean();
|
||||
$this->assertEqual("- some great test case", $buffer);
|
||||
unset($buffer);
|
||||
|
||||
$random = rand(100, 200);
|
||||
ob_start();
|
||||
$dox->paintMethodStart("testRandomNumberIs{$random}");
|
||||
$buffer = ob_get_clean();
|
||||
$this->assertEqual("- random number is {$random}", $buffer);
|
||||
}
|
||||
|
||||
function testDoesNotOutputAnythingOnNoneTestMethods() {
|
||||
$dox = new TestDoxReporter();
|
||||
ob_start();
|
||||
$dox->paintMethodStart('nonMatchingMethod');
|
||||
$buffer = ob_get_clean();
|
||||
$this->assertEqual('', $buffer);
|
||||
}
|
||||
|
||||
function testPaintMethodAddLineBreak() {
|
||||
$dox = new TestDoxReporter();
|
||||
ob_start();
|
||||
$dox->paintMethodEnd('someMethod');
|
||||
$buffer = ob_get_clean();
|
||||
$this->assertEqual("\n", $buffer);
|
||||
}
|
||||
|
||||
function testProperlySpacesSingleLettersInMethodName() {
|
||||
$dox = new TestDoxReporter();
|
||||
ob_start();
|
||||
$dox->paintMethodStart('testAVerySimpleAgainAVerySimpleMethod');
|
||||
$buffer = ob_get_clean();
|
||||
$this->assertEqual('- a very simple again a very simple method', $buffer);
|
||||
}
|
||||
|
||||
function testOnFailureThisPrintsFailureNotice() {
|
||||
$dox = new TestDoxReporter();
|
||||
ob_start();
|
||||
$dox->paintFail('');
|
||||
$buffer = ob_get_clean();
|
||||
$this->assertEqual(' [FAILED]', $buffer);
|
||||
}
|
||||
|
||||
function testWhenMatchingMethodNamesTestPrefixIsCaseInsensitive() {
|
||||
$dox = new TestDoxReporter();
|
||||
ob_start();
|
||||
$dox->paintMethodStart('TESTSupportsAllUppercaseTestPrefixEvenThoughIDoNotKnowWhyYouWouldDoThat');
|
||||
$buffer = ob_get_clean();
|
||||
$this->assertEqual(
|
||||
'- supports all uppercase test prefix even though i do not know why you would do that',
|
||||
$buffer
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user