00001 <?php
00002
00003
00009 class UnitTestCase extends SimpleTestCase {
00010
00018 function UnitTestCase($label = false) {
00019 if (!$label) {
00020 $label = get_class($this);
00021 }
00022 $this->SimpleTestCase($label);
00023 }
00024
00034 function assertTrue($result, $message = FALSE, $group = 'Other') {
00035 return $this->assert(new TrueExpectation(), $result, $message, $group);
00036 }
00037
00048 function assertFalse($result, $message = '%s', $group = 'Other') {
00049 $dumper = &new SimpleDumper();
00050 $message = sprintf($message, 'Expected false, got [' . $dumper->describeValue($result) . ']');
00051 return $this->assertTrue(!$result, $message, $group);
00052 }
00053
00061 function assertNull($value, $message = '%s', $group = 'Other') {
00062 $dumper = &new SimpleDumper();
00063 $message = sprintf($message, '[' . $dumper->describeValue($value) . '] should be null');
00064 return $this->assertTrue(!isset($value), $message, $group);
00065 }
00066
00074 function assertNotNull($value, $message = '%s', $group = 'Other') {
00075 $dumper = &new SimpleDumper();
00076 $message = sprintf($message, '[' . $dumper->describeValue($value) . '] should not be null');
00077 return $this->assertTrue(isset($value), $message, $group);
00078 }
00079
00089 function assertEqual($first, $second, $message = '%s', $group = 'Other') {
00090 $dumper = &new SimpleDumper();
00091 $message = sprintf($message, 'Expected ' . $dumper->describeValue($first) . ', got [' . $dumper->describeValue($second) . ']');
00092 $this->assertTrue($first == $second, $message, $group);
00093 }
00094
00104 function assertNotEqual($first, $second, $message = '%s', $group = 'Other') {
00105 $dumper = &new SimpleDumper();
00106 $message = sprintf($message, 'Expected ' . $dumper->describeValue($first) . ', not equal to ' . $dumper->describeValue($second));
00107 $this->assertTrue($first != $second, $message, $group);
00108 }
00109
00119 function assertIdentical($first, $second, $message = '%s', $group = 'Other') {
00120 $dumper = &new SimpleDumper();
00121 $message = sprintf($message, 'Expected ' . $dumper->describeValue($first) . ', got [' . $dumper->describeValue($second) . ']');
00122 $this->assertTrue($first === $second, $message, $group);
00123 }
00124
00134 function assertNotIdentical($first, $second, $message = '%s', $group = 'Other') {
00135 $dumper = &new SimpleDumper();
00136 $message = sprintf($message, 'Expected ' . $dumper->describeValue($first) . ', not identical to ' . $dumper->describeValue($second));
00137 $this->assertTrue($first !== $second, $message, $group);
00138 }
00139
00150 function assertPattern($pattern, $subject, $message = '%s', $group = 'Other') {
00151 $dumper = &new SimpleDumper();
00152 $replace = 'Pattern ' . $pattern . ' detected in [' . $dumper->describeValue($subject) . ']';
00153 $found = preg_match($pattern, $subject, $matches);
00154 if ($found) {
00155 $position = strpos($subject, $matches[0]);
00156 $replace .= ' in region [' . $dumper->clipString($subject, 100, $position) . ']';
00157 }
00158 $message = sprintf($message, $replace);
00159 $this->assertTrue($found, $message, $group);
00160 }
00161
00172 function assertNoPattern($pattern, $subject, $message = '%s', $group = 'Other') {
00173 $dumper = &new SimpleDumper();
00174 $found = preg_match($pattern, $subject);
00175 $message = sprintf($message, 'Pattern ' . $pattern . ' not detected in [' . $dumper->describeValue($subject) . ']');
00176 $this->assertFalse($found, $message, $group = 'Other');
00177 }
00178 }