Skip to content

Commit

Permalink
Merge pull request #7 from DEVizzent/FIX-preg_match_and_bestDiff
Browse files Browse the repository at this point in the history
FIX preg_match and bestDiff
  • Loading branch information
DEVizzent authored Apr 28, 2023
2 parents b8f45a4 + d0ae61f commit 23547e8
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/MockServerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,19 @@ public function seeMockRequestWasCalled(string $expectationId, ?int $times = nul
$this->mockserver->verify($expectationId, $times);
} catch (AssertionFailedError $exception) {
//throw $exception;
preg_match('#(.|\n)* expected:<(?<expected>\{(.|\n)*\})> but was:<(.|\n)*>#', $exception->getMessage(), $matches);
preg_match('#.* expected:<(?<expected>\{.*\})> but was:<.*>#s', $exception->getMessage(), $matches);
if (!isset($matches['expected'])) {
throw $exception;
}
$expected = json_decode($matches['expected'], true);
$notMatchedRequests = $this->mockserver->getNotMatchedRequests();
$currentSimilityRatio = 0;
$bestDiff = '';
$expectedFormatted = $this->formatMockServerRequest($expected);
foreach ($notMatchedRequests as $notMatchedRequest) {
$diff = DiffHelper::calculate($expectedFormatted, $this->formatMockServerRequest($notMatchedRequest));
$statistics = DiffHelper::getStatistics();
$similityRatio = $statistics['unmodified'] - $statistics['inserted'] - $statistics['deleted'];
if ($currentSimilityRatio < $similityRatio) {
if (!isset($currentSimilityRatio) || $currentSimilityRatio < $similityRatio) {
$currentSimilityRatio = $similityRatio;
$bestDiff = $diff;
}
Expand Down

0 comments on commit 23547e8

Please sign in to comment.