unit_tester.php
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· PHP 代码 · 共 420 行 · 第 1/2 页
PHP
420 行
/**
* Will trigger a pass if the two parameters have
* the different value or different type.
* @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 assertNotIdentical($first, $second, $message = '%s') {
return $this->assert(
new NotIdenticalExpectation($first),
$second,
$message);
}
/**
* Will trigger a pass if both parameters refer
* to the same object. Fail otherwise.
* @param mixed $first Object reference to check.
* @param mixed $second Hopefully the same object.
* @param string $message Message to display.
* @return boolean True on pass
* @access public
*/
function assertReference(&$first, &$second, $message = '%s') {
$dumper = &new SimpleDumper();
$message = sprintf(
$message,
'[' . $dumper->describeValue($first) .
'] and [' . $dumper->describeValue($second) .
'] should reference the same object');
return $this->assertTrue(
SimpleTestCompatibility::isReference($first, $second),
$message);
}
/**
* Will trigger a pass if both parameters refer
* to different objects. Fail otherwise. The objects
* have to be identical though.
* @param mixed $first Object reference to check.
* @param mixed $second Hopefully not the same object.
* @param string $message Message to display.
* @return boolean True on pass
* @access public
*/
function assertClone(&$first, &$second, $message = '%s') {
$dumper = &new SimpleDumper();
$message = sprintf(
$message,
'[' . $dumper->describeValue($first) .
'] and [' . $dumper->describeValue($second) .
'] should not be the same object');
$identical = &new IdenticalExpectation($first);
return $this->assertTrue(
$identical->test($second) &&
! SimpleTestCompatibility::isReference($first, $second),
$message);
}
/**
* @deprecated
*/
function assertCopy(&$first, &$second, $message = "%s") {
$dumper = &new SimpleDumper();
$message = sprintf(
$message,
"[" . $dumper->describeValue($first) .
"] and [" . $dumper->describeValue($second) .
"] should not be the same object");
return $this->assertFalse(
SimpleTestCompatibility::isReference($first, $second),
$message);
}
/**
* Will trigger a pass if the Perl regex pattern
* is found in the subject. Fail otherwise.
* @param string $pattern Perl regex to look for including
* the regex delimiters.
* @param string $subject String to search in.
* @param string $message Message to display.
* @return boolean True on pass
* @access public
*/
function assertPattern($pattern, $subject, $message = '%s') {
return $this->assert(
new PatternExpectation($pattern),
$subject,
$message);
}
/**
* @deprecated
*/
function assertWantedPattern($pattern, $subject, $message = '%s') {
return $this->assertPattern($pattern, $subject, $message);
}
/**
* Will trigger a pass if the perl regex pattern
* is not present in subject. Fail if found.
* @param string $pattern Perl regex to look for including
* the regex delimiters.
* @param string $subject String to search in.
* @param string $message Message to display.
* @return boolean True on pass
* @access public
*/
function assertNoPattern($pattern, $subject, $message = '%s') {
return $this->assert(
new NoPatternExpectation($pattern),
$subject,
$message);
}
/**
* @deprecated
*/
function assertNoUnwantedPattern($pattern, $subject, $message = '%s') {
return $this->assertNoPattern($pattern, $subject, $message);
}
/**
* @deprecated
*/
function swallowErrors() {
$context = &SimpleTest::getContext();
$queue = &$context->get('SimpleErrorQueue');
$queue->clear();
}
/**
* @deprecated
*/
function assertNoErrors($message = '%s') {
$context = &SimpleTest::getContext();
$queue = &$context->get('SimpleErrorQueue');
return $queue->assertNoErrors($message);
}
/**
* @deprecated
*/
function assertError($expected = false, $message = '%s') {
$context = &SimpleTest::getContext();
$queue = &$context->get('SimpleErrorQueue');
return $queue->assertError($this->_coerceExpectation($expected), $message);
}
/**
* Prepares for an error. If the error mismatches it
* passes through, otherwise it is swallowed. Any
* left over errors trigger failures.
* @param SimpleExpectation/string $expected The error to match.
* @param string $message Message on failure.
* @access public
*/
function expectError($expected = false, $message = '%s') {
$context = &SimpleTest::getContext();
$queue = &$context->get('SimpleErrorQueue');
$queue->expectError($this->_coerceExpectation($expected), $message);
}
/**
* Prepares for an exception. If the error mismatches it
* passes through, otherwise it is swallowed. Any
* left over errors trigger failures.
* @param SimpleExpectation/Exception $expected The error to match.
* @param string $message Message on failure.
* @access public
*/
function expectException($expected = false, $message = '%s') {
$context = &SimpleTest::getContext();
$queue = &$context->get('SimpleExceptionTrap');
// :HACK: Directly substituting in seems to cause a segfault with
// Zend Optimizer on some systems
$line = $this->getAssertionLine();
$queue->expectException($expected, $message . $line);
}
/**
* Creates an equality expectation if the
* object/value is not already some type
* of expectation.
* @param mixed $expected Expected value.
* @return SimpleExpectation Expectation object.
* @access private
*/
function _coerceExpectation($expected) {
if ($expected == false) {
return new TrueExpectation();
}
if (SimpleTestCompatibility::isA($expected, 'SimpleExpectation')) {
return $expected;
}
return new EqualExpectation(
is_string($expected) ? str_replace('%', '%%', $expected) : $expected);
}
/**
* @deprecated
*/
function assertErrorPattern($pattern, $message = '%s') {
return $this->assertError(new PatternExpectation($pattern), $message);
}
}
?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?