unit_tester.php
来自「一款可以和GOOGLE媲美的开源统计系统,运用AJAX.功能强大. 无色提示:」· PHP 代码 · 共 417 行 · 第 1/2 页
PHP
417 行
<?php /** * base include file for SimpleTest * @package SimpleTest * @subpackage UnitTester * @version $Id: unit_tester.php 163 2008-01-14 04:40:16Z matt $ */ /**#@+ * include other SimpleTest class files */ require_once(dirname(__FILE__) . '/test_case.php'); require_once(dirname(__FILE__) . '/dumper.php'); /**#@-*/ /** * Standard unit test class for day to day testing * of PHP code XP style. Adds some useful standard * assertions. * @package SimpleTest * @subpackage UnitTester */ class UnitTestCase extends SimpleTestCase { /** * Creates an empty test case. Should be subclassed * with test methods for a functional test case. * @param string $label Name of test case. Will use * the class name if none specified. * @access public */ function UnitTestCase($label = false) { if (! $label) { $label = get_class($this); } $this->SimpleTestCase($label); } /** * Called from within the test methods to register * passes and failures. * @param boolean $result Pass on true. * @param string $message Message to display describing * the test state. * @return boolean True on pass * @access public */ function assertTrue($result, $message = false) { return $this->assert(new TrueExpectation(), $result, $message); } /** * Will be true on false and vice versa. False * is the PHP definition of false, so that null, * empty strings, zero and an empty array all count * as false. * @param boolean $result Pass on false. * @param string $message Message to display. * @return boolean True on pass * @access public */ function assertFalse($result, $message = '%s') { return $this->assert(new FalseExpectation(), $result, $message); } /** * Will be true if the value is null. * @param null $value Supposedly null value. * @param string $message Message to display. * @return boolean True on pass * @access public */ function assertNull($value, $message = '%s') { $dumper = &new SimpleDumper(); $message = sprintf( $message, '[' . $dumper->describeValue($value) . '] should be null'); return $this->assertTrue(! isset($value), $message); } /** * Will be true if the value is set. * @param mixed $value Supposedly set value. * @param string $message Message to display. * @return boolean True on pass. * @access public */ function assertNotNull($value, $message = '%s') { $dumper = &new SimpleDumper(); $message = sprintf( $message, '[' . $dumper->describeValue($value) . '] should not be null'); return $this->assertTrue(isset($value), $message); } /** * Type and class test. Will pass if class * matches the type name or is a subclass or * if not an object, but the type is correct. * @param mixed $object Object to test. * @param string $type Type name as string. * @param string $message Message to display. * @return boolean True on pass. * @access public */ function assertIsA($object, $type, $message = '%s') { return $this->assert( new IsAExpectation($type), $object, $message); } /** * Type and class mismatch test. Will pass if class * name or underling type does not match the one * specified. * @param mixed $object Object to test. * @param string $type Type name as string. * @param string $message Message to display. * @return boolean True on pass. * @access public */ function assertNotA($object, $type, $message = '%s') { return $this->assert( new NotAExpectation($type), $object, $message); } /** * Will trigger a pass if the two parameters have * the same value only. Otherwise a fail. * @param mixed $first Value to compare. * @param mixed $second Value to compare. * @param string $message Message to display. * @return boolean True on pass * @access public */ function assertEqual($first, $second, $message = '%s') { return $this->assert( new EqualExpectation($first), $second, $message); } /** * Will trigger a pass if the two parameters have * a different value. Otherwise a fail. * @param mixed $first Value to compare. * @param mixed $second Value to compare. * @param string $message Message to display. * @return boolean True on pass * @access public */ function assertNotEqual($first, $second, $message = '%s') { return $this->assert( new NotEqualExpectation($first), $second, $message); } /** * Will trigger a pass if the if the first parameter * is near enough to the second by the margin. * @param mixed $first Value to compare. * @param mixed $second Value to compare. * @param mixed $margin Fuzziness of match. * @param string $message Message to display. * @return boolean True on pass * @access public */ function assertWithinMargin($first, $second, $margin, $message = '%s') { return $this->assert( new WithinMarginExpectation($first, $margin), $second, $message); } /** * Will trigger a pass if the two parameters differ * by more than the margin. * @param mixed $first Value to compare. * @param mixed $second Value to compare. * @param mixed $margin Fuzziness of match. * @param string $message Message to display. * @return boolean True on pass * @access public */ function assertOutsideMargin($first, $second, $margin, $message = '%s') { return $this->assert( new OutsideMarginExpectation($first, $margin), $second, $message); } /** * Will trigger a pass if the two parameters have * the same value and same type. Otherwise a fail. * @param mixed $first Value to compare. * @param mixed $second Value to compare. * @param string $message Message to display. * @return boolean True on pass * @access public */ function assertIdentical($first, $second, $message = '%s') { return $this->assert( new IdenticalExpectation($first), $second, $message);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?