当前位置: 首页>>代码示例>>PHP>>正文


PHP PHPUnit_Util_Diff类代码示例

本文整理汇总了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;
     }
 }
开发者ID:pavan-git,项目名称:visualphpunit,代码行数:57,代码来源:Object.php

示例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);
 }
开发者ID:proofek,项目名称:phpunit,代码行数:19,代码来源:String.php

示例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;
 }
开发者ID:delkyd,项目名称:sugarcrm_dev,代码行数:46,代码来源:Array.php

示例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 . "&amp;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";
 }
开发者ID:coder-d,项目名称:payment_library,代码行数:38,代码来源:CakeHtmlReporter.php

示例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";
 }
开发者ID:dudasc,项目名称:site-fescjj,代码行数:33,代码来源:CakeHtmlReporter.php

示例6: getDiff

 /**
  * @return string
  */
 public function getDiff()
 {
     return $this->actualAsString || $this->expectedAsString ? PHPUnit_Util_Diff::diff($this->expectedAsString, $this->actualAsString) : '';
 }
开发者ID:altesien,项目名称:FinalProject,代码行数:7,代码来源:ComparisonFailure.php

示例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'));
 }
开发者ID:deepakb,项目名称:test-driven-development-example,代码行数:10,代码来源:DiffTest.php

示例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'));
 }
开发者ID:rtwo,项目名称:phpunit,代码行数:7,代码来源:DiffTest.php

示例9: additionalFailureDescription

 protected function additionalFailureDescription($other)
 {
     return PHPUnit_Util_Diff::diff($this->string, $other);
 }
开发者ID:nbalonso,项目名称:MunkiFace,代码行数:4,代码来源:StringMatches.php

示例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());
     }
 }
开发者ID:robo47,项目名称:php-manipulator,代码行数:17,代码来源:TokensMatchTest.php

示例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;
 }
开发者ID:robo47,项目名称:php-manipulator,代码行数:12,代码来源:TokensMatch.php

示例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);
 }
开发者ID:jeanCarloMachado,项目名称:challenges,代码行数:16,代码来源:StringMatches.php


注:本文中的PHPUnit_Util_Diff类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。