Skip to content

Commit 23547e8

Browse files
authored
Merge pull request #7 from DEVizzent/FIX-preg_match_and_bestDiff
FIX preg_match and bestDiff
2 parents b8f45a4 + d0ae61f commit 23547e8

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/MockServerHelper.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,19 @@ public function seeMockRequestWasCalled(string $expectationId, ?int $times = nul
9090
$this->mockserver->verify($expectationId, $times);
9191
} catch (AssertionFailedError $exception) {
9292
//throw $exception;
93-
preg_match('#(.|\n)* expected:<(?<expected>\{(.|\n)*\})> but was:<(.|\n)*>#', $exception->getMessage(), $matches);
93+
preg_match('#.* expected:<(?<expected>\{.*\})> but was:<.*>#s', $exception->getMessage(), $matches);
9494
if (!isset($matches['expected'])) {
9595
throw $exception;
9696
}
9797
$expected = json_decode($matches['expected'], true);
9898
$notMatchedRequests = $this->mockserver->getNotMatchedRequests();
99-
$currentSimilityRatio = 0;
10099
$bestDiff = '';
101100
$expectedFormatted = $this->formatMockServerRequest($expected);
102101
foreach ($notMatchedRequests as $notMatchedRequest) {
103102
$diff = DiffHelper::calculate($expectedFormatted, $this->formatMockServerRequest($notMatchedRequest));
104103
$statistics = DiffHelper::getStatistics();
105104
$similityRatio = $statistics['unmodified'] - $statistics['inserted'] - $statistics['deleted'];
106-
if ($currentSimilityRatio < $similityRatio) {
105+
if (!isset($currentSimilityRatio) || $currentSimilityRatio < $similityRatio) {
107106
$currentSimilityRatio = $similityRatio;
108107
$bestDiff = $diff;
109108
}

0 commit comments

Comments
 (0)