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


PHP PHPUnit_Framework_ComparisonFailure::diffIdentical方法代码示例

本文整理汇总了PHP中PHPUnit_Framework_ComparisonFailure::diffIdentical方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Framework_ComparisonFailure::diffIdentical方法的具体用法?PHP PHPUnit_Framework_ComparisonFailure::diffIdentical怎么用?PHP PHPUnit_Framework_ComparisonFailure::diffIdentical使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHPUnit_Framework_ComparisonFailure的用法示例。


在下文中一共展示了PHPUnit_Framework_ComparisonFailure::diffIdentical方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 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

示例3: fail

 /**
  * @param   mixed   $other The value passed to evaluate() which failed the
  *                         constraint check.
  * @param   string  $description A string with extra description of what was
  *                               going on while the evaluation failed.
  * @param   boolean $not Flag to indicate negation.
  * @throws  PHPUnit_Framework_ExpectationFailedException
  */
 public function fail($other, $description, $not = FALSE)
 {
     $failureDescription = $this->failureDescription($other, $description, $not);
     if (!$not) {
         throw new PHPUnit_Framework_ExpectationFailedException($failureDescription, PHPUnit_Framework_ComparisonFailure::diffIdentical($this->value, $other), $description);
     } else {
         throw new PHPUnit_Framework_ExpectationFailedException($failureDescription, NULL);
     }
 }
开发者ID:qcodo,项目名称:qcodo-website,代码行数:17,代码来源:IsIdentical.php

示例4: toString

 /**
  * Returns a string describing the difference between the expected and the
  * actual array.
  *
  * @note Diffing is only done for one level.
  */
 public function toString()
 {
     if ($this->hasDiff()) {
         return $this->diff(print_r($this->expected, TRUE), print_r($this->actual, TRUE));
     }
     $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], $this->message . "array key <{$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) {
         $expectedValue = $this->expected[$expectedKey];
         $diff .= "array key <{$expectedKey}>: only in expected <{$expectedValue}>\n";
     }
     foreach ($actualOnly as $actualKey) {
         $actualValue = $this->actual[$actualKey];
         $diff .= "array key <{$actualKey}>: only in actual <{$actualValue}>\n";
     }
     return $diff;
 }
开发者ID:dalinhuang,项目名称:shopexts,代码行数:41,代码来源:Array.php


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