3 * adapter for SimpleTest to use PEAR PHPUnit test cases
5 * @subpackage Extensions
6 * @version $Id: pear_test_case.php,v 1.8 2005/08/03 23:25:19 lastcraft Exp $
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
::assertTrue(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
::assertTrue(!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");
89 return $this->assertTrue(
90 SimpleTestCompatibility
::isReference($first, $second),
95 * In PHP5 the identity test tests for the same
96 * object. This is a reference test in PHP4.
97 * @param $first First object handle.
98 * @param $second Hopefully a different handle.
99 * @param $message Message to display.
102 function assertNotSame(&$first, &$second, $message = "%s") {
103 $dumper = &new SimpleDumper();
106 "[" . $dumper->describeValue($first) .
107 "] and [" . $dumper->describeValue($second) .
108 "] should not be the same object");
109 return $this->assertFalse(
110 SimpleTestCompatibility
::isReference($first, $second),
115 * Sends pass if the test condition resolves true,
117 * @param $condition Condition to test true.
118 * @param $message Message to display.
121 function assertTrue($condition, $message = "%s") {
122 parent
::assertTrue($condition, $message);
126 * Sends pass if the test condition resolves false,
128 * @param $condition Condition to test false.
129 * @param $message Message to display.
132 function assertFalse($condition, $message = "%s") {
133 parent
::assertTrue(!$condition, $message);
137 * Tests a regex match. Needs refactoring.
138 * @param $pattern Regex to match.
139 * @param $subject String to search in.
140 * @param $message Message to display.
143 function assertRegExp($pattern, $subject, $message = "%s") {
144 $this->assert(new PatternExpectation($pattern), $subject, $message);
148 * Tests the type of a value.
149 * @param $value Value to take type of.
150 * @param $type Hoped for type.
151 * @param $message Message to display.
154 function assertType($value, $type, $message = "%s") {
155 parent
::assertTrue(gettype($value) == strtolower($type), $message);
159 * Sets equality operation to act as a simple equal
160 * comparison only, allowing a broader range of
162 * @param $loosely_typed True for broader comparison.
165 function setLooselyTyped($loosely_typed) {
166 $this->_loosely_typed
= $loosely_typed;
170 * For progress indication during
171 * a test amongst other things.
172 * @return Usually one.
175 function countTestCases() {
176 return $this->getSize();
180 * Accessor for name, normally just the class
185 return $this->getLabel();
189 * Does nothing. For compatibility only.
193 function setName($name) {