details
[platal.git] / htdocs / TESTS / simpletest / extensions / pear_test_case.php
CommitLineData
0337d704 1<?php
2 /**
3 * adapter for SimpleTest to use PEAR PHPUnit test cases
4 * @package SimpleTest
5 * @subpackage Extensions
6 * @version $Id: pear_test_case.php,v 1.3 2004/04/23 03:11:56 jsweat Exp $
7 */
8
9 /**#@+
10 * include SimpleTest files
11 */
12 require_once dirname(__FILE__).DIRECTORY_SEPARATOR
13 .'..'.DIRECTORY_SEPARATOR .'unit_tester.php';
14 require_once dirname(__FILE__).DIRECTORY_SEPARATOR
15 .'..'.DIRECTORY_SEPARATOR .'expectation.php';
16 /**#@-*/
17
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
23 */
24 class PHPUnit_TestCase extends SimpleTestCase {
25 var $_loosely_typed;
26
27 /**
28 * Constructor. Sets the test name.
29 * @param $label Test name to display.
30 * @public
31 */
32 function PHPUnit_TestCase($label = false) {
33 $this->SimpleTestCase($label);
34 $this->_loosely_typed = false;
35 }
36
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
44 */
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);
50 }
51 $this->assertExpectation($expectation, $second, $message);
52 }
53
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
59 */
60 function assertNotNull($value, $message = "%s") {
61 parent::assertTrue(isset($value), $message);
62 }
63
64 /**
65 * Passes if the value tested is null.
66 * @param $value Value to test against.
67 * @param $message Message to display.
68 * @public
69 */
70 function assertNull($value, $message = "%s") {
71 parent::assertTrue(!isset($value), $message);
72 }
73
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
81 */
82 function assertSame($first, $second, $message = "%s") {
83 $this->assertExpectation(new IdenticalExpectation($first), $second, $message);
84 }
85
86 /**
87 * In PHP5 the identity test tests for the same
88 * object. THis is a reference test in PHP4.
89 * @param $first First object handle.
90 * @param $second Hopefully a different handle.
91 * @param $message Message to display.
92 * @public
93 */
94 function assertNotSame($first, $second, $message = "%s") {
95 $this->assertExpectation(new NotIdenticalExpectation($first), $second, $message);
96 }
97
98 /**
99 * Sends pass if the test condition resolves true,
100 * a fail otherwise.
101 * @param $condition Condition to test true.
102 * @param $message Message to display.
103 * @public
104 */
105 function assertTrue($condition, $message = "%s") {
106 parent::assertTrue($condition, $message);
107 }
108
109 /**
110 * Sends pass if the test condition resolves false,
111 * a fail otherwise.
112 * @param $condition Condition to test false.
113 * @param $message Message to display.
114 * @public
115 */
116 function assertFalse($condition, $message = "%s") {
117 parent::assertTrue(!$condition, $message);
118 }
119
120 /**
121 * Tests a regex match. Needs refactoring.
122 * @param $pattern Regex to match.
123 * @param $subject String to search in.
124 * @param $message Message to display.
125 * @public
126 */
127 function assertRegExp($pattern, $subject, $message = "%s") {
128 $this->assertExpectation(
129 new WantedPatternExpectation($pattern),
130 $subject,
131 $message);
132 }
133
134 /**
135 * Tests the type of a value.
136 * @param $value Value to take type of.
137 * @param $type Hoped for type.
138 * @param $message Message to display.
139 * @public
140 */
141 function assertType($value, $type, $message = "%s") {
142 parent::assertTrue(gettype($value) == strtolower($type), $message);
143 }
144
145 /**
146 * Sets equality operation to act as a simple equal
147 * comparison only, allowing a broader range of
148 * matches.
149 * @param $loosely_typed True for broader comparison.
150 * @public
151 */
152 function setLooselyTyped($loosely_typed) {
153 $this->_loosely_typed = $loosely_typed;
154 }
155
156 /**
157 * For progress indication during
158 * a test amongst other things.
159 * @return Usually one.
160 * @public
161 */
162 function countTestCases() {
163 return $this->getSize();
164 }
165
166 /**
167 * Accessor for name, normally just the class
168 * name.
169 * @public
170 */
171 function getName() {
172 return $this->getLabel();
173 }
174
175 /**
176 * Does nothing. For compatibility only.
177 * @param $name Dummy
178 * @public
179 */
180 function setName($name) {
181 }
182 }
183?>