Created
March 7, 2019 11:09
-
-
Save ZurgInq/2a11349be61c6c0cd85a2d5ee495b68e to your computer and use it in GitHub Desktop.
php guzzle mock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mockRequest($method, $uri, $headers, $response) | |
{ | |
return function (RequestInterface $request, $options) use ($method, $uri, $headers, $response) { | |
if ($method != $request->getMethod()) { | |
throw new \LogicException("Invalid Mock: '$method'' expected"); | |
} | |
$actual = $request->getUri(); | |
if ($uri != $request->getUri()) { | |
throw new \LogicException("Invalid Mock: uri '$uri' expected, but '$actual' given"); | |
} | |
foreach ($headers as $header => $expected) { | |
if ($request->getHeaderLine($header) != $expected) { | |
throw new \LogicException("Invalid Mock: header $header: $expected expected"); | |
} | |
}; | |
return $response; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment