本文整理汇总了PHP中PHPUnit_Util_Diff类的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_Diff类的具体用法?PHP PHPUnit_Util_Diff怎么用?PHP PHPUnit_Util_Diff使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PHPUnit_Util_Diff类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toString
/**
* Returns a string describing the difference between the expected and the
* actual object.
*
* @return string
*/
public function toString()
{
$diff = PHPUnit_Util_Diff::diff(print_r($this->expected, TRUE), print_r($this->actual, TRUE));
if ($diff !== FALSE) {
return trim($diff);
}
// Fallback: Either diff is not available or the print_r() output for
// the expected and the actual object are equal (but the objects are
// not).
$expectedClass = get_class($this->expected);
$actualClass = get_class($this->actual);
if ($expectedClass !== $actualClass) {
return sprintf("%s%sexpected class <%s>\n" . '%sgot class <%s>', $this->message, $this->message != '' ? ' ' : '', $expectedClass, $this->message != '' ? str_repeat(' ', strlen($this->message) + 1) : '', $actualClass);
} else {
$expectedReflection = new ReflectionClass($expectedClass);
$actualReflection = new ReflectionClass($actualClass);
$diff = "in object of class <{$expectedClass}>:\n";
$i = 0;
foreach ($expectedReflection->getProperties() as $expectedAttribute) {
if ($expectedAttribute->isPrivate() || $expectedAttribute->isProtected()) {
continue;
}
$actualAttribute = $actualReflection->getProperty($expectedAttribute->getName());
$expectedValue = $expectedAttribute->getValue($this->expected);
$actualValue = $actualAttribute->getValue($this->actual);
if ($expectedValue !== $actualValue) {
if ($i > 0) {
$diff .= "\n";
}
++$i;
$expectedType = gettype($expectedValue);
$actualType = gettype($actualValue);
if ($expectedType !== $actualType) {
$diffObject = new PHPUnit_Framework_ComparisonFailure_Type($expectedValue, $actualValue, $this->message . 'attribute <' . $expectedAttribute->getName() . '>: ');
$diff .= $diffObject->toString();
} elseif (is_object($expectedValue)) {
if (get_class($expectedValue) !== get_class($actualValue)) {
$diffObject = new PHPUnit_Framework_ComparisonFailure_Type($expectedValue, $actualValue, $this->message . 'attribute <' . $expectedAttribute->getName() . '>: ');
$diff .= $diffObject->toString();
} else {
$diff .= 'attribute <' . $expectedAttribute->getName() . '> contains object <' . get_class($expectedValue) . '> with different attributes';
}
} else {
$diffObject = PHPUnit_Framework_ComparisonFailure::diffIdentical($expectedValue, $actualValue, $this->message . 'attribute <' . $expectedAttribute->getName() . '>: ');
$diff .= $diffObject->toString();
}
}
}
return $diff;
}
}
示例2: toString
/**
* Returns a string describing the difference between
* the expected and the actual string value.
*/
public function toString()
{
$expected = (string) $this->expected;
$actual = (string) $this->actual;
$diff = PHPUnit_Util_Diff::diff($expected, $actual);
if ($diff === FALSE) {
$diff = '';
}
if (!empty($this->message)) {
$buffer = $this->message . "\n";
} else {
$buffer = '';
}
return trim($buffer . $diff);
}
示例3: toString
/**
* Returns a string describing the difference between the expected and the
* actual array.
*
* @return string
*/
public function toString()
{
if (!$this->identical) {
ksort($this->expected);
ksort($this->actual);
}
$diff = PHPUnit_Util_Diff::diff(print_r($this->expected, TRUE), print_r($this->actual, TRUE));
if ($diff !== FALSE) {
return trim($diff);
}
// Fallback: Either diff is not available or the print_r() output for
// the expected and the actual array are equal (but the arrays are not).
$expectedOnly = array();
$actualOnly = array();
$diff = '';
foreach ($this->expected as $expectedKey => $expectedValue) {
if (!array_key_exists($expectedKey, $this->actual)) {
$expectedOnly[] = $expectedKey;
continue;
}
if ($expectedValue === $this->actual[$expectedKey]) {
continue;
}
$diffObject = PHPUnit_Framework_ComparisonFailure::diffIdentical($expectedValue, $this->actual[$expectedKey], sprintf('%sarray key %s: ', $this->message, PHPUnit_Util_Type::toString($expectedKey)));
$diff .= $diffObject->toString() . "\n";
}
foreach ($this->actual as $actualKey => $actualValue) {
if (!array_key_exists($actualKey, $this->expected)) {
$actualOnly[] = $actualKey;
continue;
}
}
foreach ($expectedOnly as $expectedKey) {
$diff .= sprintf("array key %s: only in expected %s\n", PHPUnit_Util_Type::toString($expectedKey), PHPUnit_Util_Type::toString($this->expected[$expectedKey]));
}
foreach ($actualOnly as $actualKey) {
$diff .= sprintf("array key %s: only in actual %s\n", PHPUnit_Util_Type::toString($actualKey), PHPUnit_Util_Type::toString($this->actual[$actualKey]));
}
return $diff;
}
示例4: paintFail
/**
* Paints the test failure with a breadcrumbs
* trail of the nesting test suites below the
* top level test.
*
* @param PHPUnit_Framework_AssertionFailedError $message Failure object displayed in
* the context of the other tests.
* @param mixed $test The test case to paint a failure for.
* @return void
*/
public function paintFail($message, $test)
{
$trace = $this->_getStackTrace($message);
$className = get_class($test);
$testName = $className . '::' . $test->getName() . '()';
$actualMsg = $expectedMsg = null;
if (method_exists($message, 'getComparisonFailure')) {
$failure = $message->getComparisonFailure();
if (is_object($failure)) {
$actualMsg = $failure->getActualAsString();
$expectedMsg = $failure->getExpectedAsString();
}
}
echo "<li class='fail'>\n";
echo "<span>Failed</span>";
echo "<div class='msg'><pre>" . $this->_htmlEntities($message->toString());
if (is_string($actualMsg) && is_string($expectedMsg) || is_array($actualMsg) && is_array($expectedMsg)) {
echo "<br />" . $this->_htmlEntities(PHPUnit_Util_Diff::diff($expectedMsg, $actualMsg));
}
echo "</pre></div>\n";
echo "<div class='msg'>" . __d('cake_dev', 'Test case: %s', $testName) . "</div>\n";
if (strpos($className, "PHPUnit_") === false) {
list($show, $query) = $this->_getQueryLink();
echo "<div class='msg'><a href='" . $this->baseUrl() . $query . "&filter=" . $test->getName() . "'>" . __d('cake_dev', 'Rerun only this test: %s', $testName) . "</a></div>\n";
}
echo "<div class='msg'>" . __d('cake_dev', 'Stack trace:') . '<br />' . $trace . "</div>\n";
echo "</li>\n";
}
示例5: paintFail
/**
* Paints the test failure with a breadcrumbs
* trail of the nesting test suites below the
* top level test.
*
* @param PHPUnit_Framework_AssertionFailedError $message Failure object displayed in
* the context of the other tests.
* @param mixed $test
* @return void
*/
public function paintFail($message, $test)
{
$trace = $this->_getStackTrace($message);
$testName = get_class($test) . '(' . $test->getName() . ')';
$actualMsg = $expectedMsg = null;
if (method_exists($message, 'getComparisonFailure')) {
$failure = $message->getComparisonFailure();
if (is_object($failure)) {
$actualMsg = $failure->getActualAsString();
$expectedMsg = $failure->getExpectedAsString();
}
}
echo "<li class='fail'>\n";
echo "<span>Failed</span>";
echo "<div class='msg'><pre>" . $this->_htmlEntities($message->toString());
if (is_string($actualMsg) && is_string($expectedMsg) || is_array($actualMsg) && is_array($expectedMsg)) {
echo "<br />" . $this->_htmlEntities(PHPUnit_Util_Diff::diff($expectedMsg, $actualMsg));
}
echo "</pre></div>\n";
echo "<div class='msg'>" . __d('cake_dev', 'Test case: %s', $testName) . "</div>\n";
echo "<div class='msg'>" . __d('cake_dev', 'Stack trace:') . '<br />' . $trace . "</div>\n";
echo "</li>\n";
}
示例6: getDiff
/**
* @return string
*/
public function getDiff()
{
return $this->actualAsString || $this->expectedAsString ? PHPUnit_Util_Diff::diff($this->expectedAsString, $this->actualAsString) : '';
}
示例7: testComparisonErrorOverlapingMatches2_toArray
/**
* @covers PHPUnit_Util_Diff::diffToArray
*/
public function testComparisonErrorOverlapingMatches2_toArray()
{
$diff = array();
$diff[] = array('abcdde', self::REMOVED);
$diff[] = array('abcde', self::ADDED);
$this->assertEquals($diff, PHPUnit_Util_Diff::diffToArray('abcdde', 'abcde'));
}
示例8: testComparisonErrorOverlapingMatches2
/**
* @covers PHPUnit_Util_Diff::diff
*/
public function testComparisonErrorOverlapingMatches2()
{
$this->assertEquals("--- Expected\n+++ Actual\n@@ @@\n-abcdde\n+abcde\n", PHPUnit_Util_Diff::diff('abcdde', 'abcde'));
}
示例9: additionalFailureDescription
protected function additionalFailureDescription($other)
{
return PHPUnit_Util_Diff::diff($this->string, $other);
}
示例10: testFailAndFailureDescriptionWithDifferentLinenumbers
/**
* @covers \Tests\Constraint\TokensMatch::failureDescription
*/
public function testFailAndFailureDescriptionWithDifferentLinenumbers()
{
$expected = new Token('blub', null, '5');
$other = new Token('blub', null, '4');
$tokenMatch = new TokensMatch($expected, true);
$message = PHP_EOL . \PHPUnit_Util_Diff::diff((string) $expected, (string) $other);
$message = 'Failed asserting that Tokens are different: [linenumber]' . $message . '.';
try {
$tokenMatch->evaluate($other);
$this->fail('no exception thrown');
} catch (\PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertEquals($message, $e->getMessage());
}
}
示例11: failureDescription
/**
* @param mixed $other
* @param string $description
* @param boolean $not
* @return string
*/
protected function failureDescription($other)
{
$message = PHP_EOL . \PHPUnit_Util_Diff::diff((string) $this->_expectedToken, (string) $other);
$difference = $this->_difference;
return 'Tokens are different: [' . $difference . ']' . $message;
}
示例12: additionalFailureDescription
protected function additionalFailureDescription($other)
{
$from = preg_split('(\\r\\n|\\r|\\n)', $this->string);
$to = preg_split('(\\r\\n|\\r|\\n)', $other);
foreach ($from as $index => $line) {
if (isset($to[$index]) && $line !== $to[$index]) {
$line = $this->createPatternFromFormat($line);
if (preg_match($line, $to[$index]) > 0) {
$from[$index] = $to[$index];
}
}
}
$this->string = join("\n", $from);
$other = join("\n", $to);
return PHPUnit_Util_Diff::diff($this->string, $other);
}