00001 <?php 00002 // $Id: expectation.php,v 1.2 2008/05/10 06:55:09 dries Exp $ 00003 00011 class SimpleExpectation { 00012 var $_dumper = false; 00013 var $_message; 00014 00020 function SimpleExpectation($message = '%s') { 00021 $this->_message = $message; 00022 } 00023 00031 function test($compare) {} 00032 00041 function testMessage($compare) {} 00042 00052 function overlayMessage($compare, $dumper) { 00053 $this->_dumper = $dumper; 00054 return sprintf($this->_message, $this->testMessage($compare)); 00055 } 00056 00062 function &_getDumper() { 00063 if (!$this->_dumper) { 00064 $dumper = &new SimpleDumper(); 00065 return $dumper; 00066 } 00067 return $this->_dumper; 00068 } 00069 00080 function isExpectation($expectation) { 00081 return is_object($expectation) && is_a($expectation, 'SimpleExpectation'); 00082 } 00083 } 00084 00090 class AnythingExpectation extends SimpleExpectation { 00091 00098 function test($compare) { 00099 return true; 00100 } 00101 00109 function testMessage($compare) { 00110 $dumper = &$this->_getDumper(); 00111 return 'Anything always matches [' . $dumper->describeValue($compare) . ']'; 00112 } 00113 } 00114 00120 class TrueExpectation extends SimpleExpectation { 00121 00128 function test($compare) { 00129 return (boolean)$compare; 00130 } 00131 00139 function testMessage($compare) { 00140 $dumper = &$this->_getDumper(); 00141 return 'Expected true, got [' . $dumper->describeValue($compare) . ']'; 00142 } 00143 } 00144
1.5.5