You are here

protected function PHPUnit_Framework_Constraint_StringMatches::additionalFailureDescription in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/phpunit/phpunit/src/Framework/Constraint/StringMatches.php \PHPUnit_Framework_Constraint_StringMatches::additionalFailureDescription()

Return additional failure description where needed

The function can be overridden to provide additional failure information like a diff

Parameters

mixed $other Evaluated value or object.:

Return value

string

Overrides PHPUnit_Framework_Constraint::additionalFailureDescription

File

vendor/phpunit/phpunit/src/Framework/Constraint/StringMatches.php, line 44

Class

PHPUnit_Framework_Constraint_StringMatches
...

Code

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 = implode("\n", $from);
  $other = implode("\n", $to);
  $differ = new Differ("--- Expected\n+++ Actual\n");
  return $differ
    ->diff($this->string, $other);
}