Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Formatter/Formatter.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ public function objectToString($obj)
*/
protected function getTemplateVars(TemplateInterface $template)
{
$differExists = (property_exists($this->match, "differ") && is_callable($this->match->differ));
$vars = [
'expected' => $this->match->getExpected(),
'actual' => $this->match->getActual(),
'diff' => $differExists?call_user_func($this->match->differ, $this->match->getActual(), $this->match->getExpected()):"",
];

if ($tplVars = $template->getTemplateVars()) {
Expand Down
7 changes: 6 additions & 1 deletion src/Matcher/AbstractMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ public function match($actual = '')
{
$isMatch = $this->doMatch($actual);
$isNegated = $this->isNegated();
$fulfillsExpectation = ($isMatch xor $isNegated);

return new Match($isMatch xor $isNegated, $this->expected, $actual, $isNegated);
$match = new Match($fulfillsExpectation, $this->expected, $actual, $isNegated);
if ((!$fulfillsExpectation) && method_exists($this, "differ")) {
$match->differ = [$this, "differ"];
}
return $match;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Matcher/SameMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*/
class SameMatcher extends AbstractMatcher
{
public function differ($actual, $expected) {
return "THE CALCULATED DIFF";
}

/**
* Match if the actual value is identical to the expected value using an ===
* comparison.
Expand All @@ -31,7 +35,7 @@ public function doMatch($actual)
public function getDefaultTemplate()
{
return new ArrayTemplate([
'default' => 'Expected {{actual}} to be identical to {{expected}}',
'default' => 'Expected {{actual}} to be identical to {{expected}}. Difference: {{diff}}',
'negated' => 'Expected {{actual}} not to be identical to {{expected}}',
]);
}
Expand Down