| [ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 3 4 /** 5 * PHP Version 4 6 * 7 * Copyright (c) 2002-2005, Sebastian Bergmann <sb@sebastian-bergmann.de>. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 14 * * Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 17 * * Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in 19 * the documentation and/or other materials provided with the 20 * distribution. 21 * 22 * * Neither the name of Sebastian Bergmann nor the names of his 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 29 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 30 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 32 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 33 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 34 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 36 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 * 39 * @category Testing 40 * @package PHPUnit 41 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> 42 * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> 43 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 44 * @version CVS: $Id: TestCase.php,v 1.21 2005/11/10 09:47:14 sebastian Exp $ 45 * @link http://pear.php.net/package/PHPUnit 46 * @since File available since Release 1.0.0 47 */ 48 49 lt_include(PHPUNIT_CLASS_PATH.'PHPUnit/Assert.php'); 50 lt_include(PHPUNIT_CLASS_PATH.'PHPUnit/TestResult.php'); 51 //lt_include( PLOG_CLASS_PATH."class/test/helpers/lifetypeassert.class.php" ); 52 53 /** 54 * A TestCase defines the fixture to run multiple tests. 55 * 56 * To define a TestCase 57 * 58 * 1) Implement a subclass of PHPUnit_TestCase. 59 * 2) Define instance variables that store the state of the fixture. 60 * 3) Initialize the fixture state by overriding setUp(). 61 * 4) Clean-up after a test by overriding tearDown(). 62 * 63 * Each test runs in its own fixture so there can be no side effects 64 * among test runs. 65 * 66 * Here is an example: 67 * 68 * <code> 69 * <?php 70 * class MathTest extends PHPUnit_TestCase { 71 * var $fValue1; 72 * var $fValue2; 73 * 74 * function MathTest($name) { 75 * $this->PHPUnit_TestCase($name); 76 * } 77 * 78 * function setUp() { 79 * $this->fValue1 = 2; 80 * $this->fValue2 = 3; 81 * } 82 * } 83 * ?> 84 * </code> 85 * 86 * For each test implement a method which interacts with the fixture. 87 * Verify the expected results with assertions specified by calling 88 * assert with a boolean. 89 * 90 * <code> 91 * <?php 92 * function testPass() { 93 * $this->assertTrue($this->fValue1 + $this->fValue2 == 5); 94 * } 95 * ?> 96 * </code> 97 * 98 * @category Testing 99 * @package PHPUnit 100 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> 101 * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> 102 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 103 * @version Release: @package_version@ 104 * @link http://pear.php.net/package/PHPUnit 105 * @since Class available since Release 1.0.0 106 */ 107 class PHPUnit_TestCase extends PHPUnit_Assert { 108 /** 109 * @var boolean 110 * @access private 111 */ 112 var $_failed = FALSE; 113 114 /** 115 * The name of the test case. 116 * 117 * @var string 118 * @access private 119 */ 120 var $_name = ''; 121 122 /** 123 * PHPUnit_TestResult object 124 * 125 * @var object 126 * @access private 127 */ 128 var $_result; 129 130 /** 131 * Constructs a test case with the given name. 132 * 133 * @param string 134 * @access public 135 */ 136 function PHPUnit_TestCase($name = FALSE) { 137 if ($name !== FALSE) { 138 $this->setName($name); 139 } 140 } 141 142 /** 143 * Counts the number of test cases executed by run(TestResult result). 144 * 145 * @return integer 146 * @access public 147 */ 148 function countTestCases() { 149 return 1; 150 } 151 152 /** 153 * Gets the name of a TestCase. 154 * 155 * @return string 156 * @access public 157 */ 158 function getName() { 159 return $this->_name; 160 } 161 162 /** 163 * Runs the test case and collects the results in a given TestResult object. 164 * 165 * @param object 166 * @return object 167 * @access public 168 */ 169 function run(&$result) { 170 $this->_result = &$result; 171 $this->_result->run($this); 172 173 return $this->_result; 174 } 175 176 /** 177 * Runs the bare test sequence. 178 * 179 * @access public 180 */ 181 function runBare() { 182 $this->setUp(); 183 $this->runTest(); 184 $this->tearDown(); 185 $this->pass(); 186 } 187 188 /** 189 * Override to run the test and assert its state. 190 * 191 * @access protected 192 */ 193 function runTest() { 194 call_user_func( 195 array( 196 &$this, 197 $this->_name 198 ) 199 ); 200 } 201 202 /** 203 * Sets the name of a TestCase. 204 * 205 * @param string 206 * @access public 207 */ 208 function setName($name) { 209 $this->_name = $name; 210 } 211 212 /** 213 * Returns a string representation of the test case. 214 * 215 * @return string 216 * @access public 217 */ 218 function toString() { 219 return ''; 220 } 221 222 /** 223 * Creates a default TestResult object. 224 * 225 * @return object 226 * @access protected 227 */ 228 function &createResult() { 229 return new PHPUnit_TestResult; 230 } 231 232 /** 233 * Fails a test with the given message. 234 * 235 * @param string 236 * @access protected 237 */ 238 function fail($message = '') { 239 if (function_exists('debug_backtrace')) { 240 $trace = debug_backtrace(); 241 242 if (isset($trace['1']['file'])) { 243 $message = sprintf( 244 "%s in %s:%s", 245 246 $message, 247 $trace['1']['file'], 248 $trace['1']['line'] 249 ); 250 } 251 } 252 253 $this->_result->addFailure($this, $message); 254 $this->_failed = TRUE; 255 } 256 257 /** 258 * Passes a test. 259 * 260 * @access protected 261 */ 262 function pass() { 263 if (!$this->_failed) { 264 $this->_result->addPassedTest($this); 265 } 266 } 267 268 /** 269 * Sets up the fixture, for example, open a network connection. 270 * This method is called before a test is executed. 271 * 272 * @access protected 273 * @abstract 274 */ 275 function setUp() { /* abstract */ } 276 277 /** 278 * Tears down the fixture, for example, close a network connection. 279 * This method is called after a test is executed. 280 * 281 * @access protected 282 * @abstract 283 */ 284 function tearDown() { /* abstract */ } 285 } 286 287 /* 288 * Local variables: 289 * tab-width: 4 290 * c-basic-offset: 4 291 * c-hanging-comment-ender-p: nil 292 * End: 293 */ 294 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
|