3 * adapter for SimpleTest to use PEAR PHPUnit test cases
5 * @subpackage Extensions
10 * include SimpleTest files
12 require_once(dirname(__FILE__
) . '/../dumper.php');
13 require_once(dirname(__FILE__
) . '/../compatibility.php');
14 require_once(dirname(__FILE__
) . '/../test_case.php');
15 require_once(dirname(__FILE__
) . '/../expectation.php');
19 * Adapter for PEAR PHPUnit test case to allow
20 * legacy PEAR test cases to be used with SimpleTest.
22 * @subpackage Extensions
24 class PHPUnit_TestCase
extends SimpleTestCase
{
28 * Constructor. Sets the test name.
29 * @param $label Test name to display.
32 function PHPUnit_TestCase($label = false) {
33 $this->SimpleTestCase($label);
34 $this->_loosely_typed
= false;
38 * Will test straight equality if set to loose
39 * typing, or identity if not.
40 * @param $first First value.
41 * @param $second Comparison value.
42 * @param $message Message to display.
45 function assertEquals($first, $second, $message = "%s", $delta = 0) {
46 if ($this->_loosely_typed
) {
47 $expectation = &new EqualExpectation($first);
49 $expectation = &new IdenticalExpectation($first);
51 $this->assert($expectation, $second, $message);
55 * Passes if the value tested is not null.
56 * @param $value Value to test against.
57 * @param $message Message to display.
60 function assertNotNull($value, $message = "%s") {
61 parent
::assert(new TrueExpectation(), isset($value), $message);
65 * Passes if the value tested is null.
66 * @param $value Value to test against.
67 * @param $message Message to display.
70 function assertNull($value, $message = "%s") {
71 parent
::assert(new TrueExpectation(), !isset($value), $message);
75 * In PHP5 the identity test tests for the same
76 * object. This is a reference test in PHP4.
77 * @param $first First object handle.
78 * @param $second Hopefully the same handle.
79 * @param $message Message to display.
82 function assertSame(&$first, &$second, $message = "%s") {
83 $dumper = &new SimpleDumper();
86 "[" . $dumper->describeValue($first) .
87 "] and [" . $dumper->describeValue($second) .
88 "] should reference the same object");
90 new TrueExpectation(),
91 SimpleTestCompatibility
::isReference($first, $second),
96 * In PHP5 the identity test tests for the same
97 * object. This is a reference test in PHP4.
98 * @param $first First object handle.
99 * @param $second Hopefully a different handle.
100 * @param $message Message to display.
103 function assertNotSame(&$first, &$second, $message = "%s") {
104 $dumper = &new SimpleDumper();
107 "[" . $dumper->describeValue($first) .
108 "] and [" . $dumper->describeValue($second) .
109 "] should not be the same object");
110 return $this->assert(
111 new falseExpectation(),
112 SimpleTestCompatibility
::isReference($first, $second),
117 * Sends pass if the test condition resolves true,
119 * @param $condition Condition to test true.
120 * @param $message Message to display.
123 function assertTrue($condition, $message = "%s") {
124 parent
::assert(new TrueExpectation(), $condition, $message);
128 * Sends pass if the test condition resolves false,
130 * @param $condition Condition to test false.
131 * @param $message Message to display.
134 function assertFalse($condition, $message = "%s") {
135 parent
::assert(new FalseExpectation(), $condition, $message);
139 * Tests a regex match. Needs refactoring.
140 * @param $pattern Regex to match.
141 * @param $subject String to search in.
142 * @param $message Message to display.
145 function assertRegExp($pattern, $subject, $message = "%s") {
146 $this->assert(new PatternExpectation($pattern), $subject, $message);
150 * Tests the type of a value.
151 * @param $value Value to take type of.
152 * @param $type Hoped for type.
153 * @param $message Message to display.
156 function assertType($value, $type, $message = "%s") {
157 parent
::assert(new TrueExpectation(), gettype($value) == strtolower($type), $message);
161 * Sets equality operation to act as a simple equal
162 * comparison only, allowing a broader range of
164 * @param $loosely_typed True for broader comparison.
167 function setLooselyTyped($loosely_typed) {
168 $this->_loosely_typed
= $loosely_typed;
172 * For progress indication during
173 * a test amongst other things.
174 * @return Usually one.
177 function countTestCases() {
178 return $this->getSize();
182 * Accessor for name, normally just the class
187 return $this->getLabel();
191 * Does nothing. For compatibility only.
195 function setName($name) {