mcustiel / phiremock-common

Common classes for Phiremock
GNU General Public License v3.0
3 stars 4 forks source link

#5 Closes Fix wrong order of needle/haystack in Matchers/Contains #6

Closed enduro44 closed 3 years ago

mcustiel commented 3 years ago

Hello @enduro44 I think this fix is not needed as this matcher works as expected. I will write a small unit test to verify it and will come back to you later. Thank you.

enduro44 commented 3 years ago

@mcustiel Check out phiremock-server/src/Utils/RequestExpectationComparator.php where Contains:matches is called. Http Body is passed as value (needle) and condition is set in constructor and used as haystack in strpos. Unit test should fail, I guess. And sorry I didn't write unit test myself to test this :(


private function requestBodyMatchesExpectation(ServerRequestInterface $httpRequest, Conditions $expectedRequest): bool
    {
        $bodycondition = $expectedRequest->getBody();
        if (!$bodycondition) {
            return true;
        }
        $this->logger->debug('Checking BODY against expectation');

        return $bodycondition->getMatcher()->matches($httpRequest->getBody()->__toString());
    }
`
mcustiel commented 3 years ago

Indeed it's broken. Nice catch. Thank you very much for your fix.