Skip to content

Commit 7dfc942

Browse files
committed
Simplify failure description returned by PHPMatcherConstraint
1 parent 8d08946 commit 7dfc942

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/PHPUnit/PHPMatcherConstraint.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Coduo\PHPMatcher\PHPUnit;
66

77
use Coduo\PHPMatcher\Backtrace;
8+
use Coduo\PHPMatcher\Backtrace\VoidBacktrace;
89
use Coduo\PHPMatcher\PHPMatcher;
910
use PHPUnit\Framework\Constraint\Constraint;
1011
use PHPUnit\Util\Json;
@@ -42,10 +43,13 @@ public function toString() : string
4243

4344
protected function failureDescription($other) : string
4445
{
45-
return parent::failureDescription($other)
46-
. "\nPattern: " . $this->exporter()->export($this->pattern)
47-
. "\nError: " . $this->matcher->error()
48-
. "\nBacktrace: \n" . $this->matcher->backtrace();
46+
$errorDescription = $this->matcher->error() ?: 'Value does not match given pattern';
47+
$backtrace = $this->matcher->backtrace();
48+
49+
return $backtrace instanceof VoidBacktrace
50+
? $errorDescription
51+
: $errorDescription
52+
. "\nBacktrace: \n" . $this->matcher->backtrace();
4953
}
5054

5155
protected function matches($value) : bool

0 commit comments

Comments
 (0)