Skip to content

Instantly share code, notes, and snippets.

@ZurgInq
Created March 7, 2019 11:09
Show Gist options
  • Save ZurgInq/2a11349be61c6c0cd85a2d5ee495b68e to your computer and use it in GitHub Desktop.
Save ZurgInq/2a11349be61c6c0cd85a2d5ee495b68e to your computer and use it in GitHub Desktop.
php guzzle mock
<?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