adding some strings
[moodle-linuxchix.git] / lib / simpletestlib / extensions / pear_test_case.php
blob4f9f4ad3eeb6d3bce0f1b984bcfe7e5c80d7cc9a
1 <?php
2 /**
3 * adapter for SimpleTest to use PEAR PHPUnit test cases
4 * @package SimpleTest
5 * @subpackage Extensions
6 * @version $Id$
7 */
9 /**#@+
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');
16 /**#@-*/
18 /**
19 * Adapter for PEAR PHPUnit test case to allow
20 * legacy PEAR test cases to be used with SimpleTest.
21 * @package SimpleTest
22 * @subpackage Extensions
24 class PHPUnit_TestCase extends SimpleTestCase {
25 var $_loosely_typed;
27 /**
28 * Constructor. Sets the test name.
29 * @param $label Test name to display.
30 * @public
32 function PHPUnit_TestCase($label = false) {
33 $this->SimpleTestCase($label);
34 $this->_loosely_typed = false;
37 /**
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.
43 * @public
45 function assertEquals($first, $second, $message = "%s", $delta = 0) {
46 if ($this->_loosely_typed) {
47 $expectation = &new EqualExpectation($first);
48 } else {
49 $expectation = &new IdenticalExpectation($first);
51 $this->assert($expectation, $second, $message);
54 /**
55 * Passes if the value tested is not null.
56 * @param $value Value to test against.
57 * @param $message Message to display.
58 * @public
60 function assertNotNull($value, $message = "%s") {
61 parent::assert(new TrueExpectation(), isset($value), $message);
64 /**
65 * Passes if the value tested is null.
66 * @param $value Value to test against.
67 * @param $message Message to display.
68 * @public
70 function assertNull($value, $message = "%s") {
71 parent::assert(new TrueExpectation(), !isset($value), $message);
74 /**
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.
80 * @public
82 function assertSame(&$first, &$second, $message = "%s") {
83 $dumper = &new SimpleDumper();
84 $message = sprintf(
85 $message,
86 "[" . $dumper->describeValue($first) .
87 "] and [" . $dumper->describeValue($second) .
88 "] should reference the same object");
89 return $this->assert(
90 new TrueExpectation(),
91 SimpleTestCompatibility::isReference($first, $second),
92 $message);
95 /**
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.
101 * @public
103 function assertNotSame(&$first, &$second, $message = "%s") {
104 $dumper = &new SimpleDumper();
105 $message = sprintf(
106 $message,
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),
113 $message);
117 * Sends pass if the test condition resolves true,
118 * a fail otherwise.
119 * @param $condition Condition to test true.
120 * @param $message Message to display.
121 * @public
123 function assertTrue($condition, $message = "%s") {
124 parent::assert(new TrueExpectation(), $condition, $message);
128 * Sends pass if the test condition resolves false,
129 * a fail otherwise.
130 * @param $condition Condition to test false.
131 * @param $message Message to display.
132 * @public
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.
143 * @public
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.
154 * @public
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
163 * matches.
164 * @param $loosely_typed True for broader comparison.
165 * @public
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.
175 * @public
177 function countTestCases() {
178 return $this->getSize();
182 * Accessor for name, normally just the class
183 * name.
184 * @public
186 function getName() {
187 return $this->getLabel();
191 * Does nothing. For compatibility only.
192 * @param $name Dummy
193 * @public
195 function setName($name) {