Skip to content

Commit

Permalink
Merge pull request #13 from timheilig/perf_problem_with_differ
Browse files Browse the repository at this point in the history
Perf problem with differ
  • Loading branch information
theilig authored Feb 28, 2017
2 parents 4e35222 + eea52b2 commit d207d74
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Shmock/StaticSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,20 @@ public function return_value_map($mapOfArgsToValues)

$this->will = function ($invocation) use ($mapping) {
$args = $invocation->parameters;
$differ = new \SebastianBergmann\Diff\Differ();
$diffSoFar = null;
foreach ($mapping as $map) {
list($possibleArgs, $possibleRet) = $map;
if ($possibleArgs === $args) {
return $possibleRet;
} else {
$nextDiff = $differ->diff(print_r($possibleArgs, true), print_r($args, true));
if ($diffSoFar === null || strlen($nextDiff) < strlen($diffSoFar)) {
$diffSoFar = $nextDiff;
}
}
}

$differ = new \SebastianBergmann\Diff\Differ();
$diffSoFar = null;
foreach ($mapping as $map) {
$possibleArgs = $map[0];
$nextDiff = $differ->diff(print_r($possibleArgs, true), print_r($args, true));
if ($diffSoFar === null || strlen($nextDiff) < strlen($diffSoFar)) {
$diffSoFar = $nextDiff;
}
}
throw new \PHPUnit_Framework_AssertionFailedError(sprintf("Did not expect to be called with args %s, diff with closest match is\n%s", print_r($args, true), $diffSoFar));
Expand Down

0 comments on commit d207d74

Please sign in to comment.