For more information view the full api documentation.
The first step in surface testing your API is making the request. That is done with the
HttpRequest
object.
<?php
namespace Boomerang;
class HttpRequest {
public const GET = "GET";
public const POST = "POST";
public const PUT = "PUT";
public const PATCH = "PATCH";
public const DELETE = "DELETE";
public const TRACE = "TRACE";
public const OPTIONS = "OPTIONS";
}
function __construct($endpoint [, \Boomerang\Factories\HttpResponseFactory $responseFactory = null])
$endpoint
- URI to request.$responseFactory
- A factory for creating Response objects.function setMethod($method)
Set the request method.
$req->setMethod(HttpRequest::POST);
$method
function setUrlParam($param, $value)
Set a url param by name.
$param
- The name of the param.string | int | float | array $value |
function setUrlParams(array $params)
Set outgoing params as an array of ParamName => Value
$params
- Params to setfunction setHeader($key, $value)
Set an outgoing header by name.
$key
- The name of the header.$value
- The value to set the header to.function setHeaders(array $headers)
Set outgoing headers as an array of HeaderName => Value
$headers
- Headers to setfunction setBasicAuth($username [, $password = ''])
Set outgoing basic auth header.
$username
$password
function setFormValue($key, $value)
Set a named key of the form values
Note that if there is a non-form body set, this will replace it.
$key
$value
function setBody($body)
Set the requests body
array | string $body |
function setCookiesFollowRedirects($bool)
Allows you to enable cookie’s set by server re-posting following a redirect.
Requires file system storage of a “cookie jar” file and is therefore disabled by default.
$bool
- true/false to enable/disable respectivelyfunction setCookies(array $cookies)
Set outgoing cookies as an array of CookieName => Value
$cookies
- Cookies to setfunction setCookie($key, $value)
Set a named cookies outgoing value
$key
$value
function setEndpoint($endpoint)
Sets the request URI
$endpoint
function makeRequest()
Execute the request
function setMaxRedirects($maxRedirects)
Set the maximum number of redirects(hops) a request should follow.
$maxRedirects
Validators are used to define your expectations for the response.
function expectStatus([ $expected_status = 200 [, $hop = null]])
Verify that the HTTP response code is as expected.
$expected_status
$hop
- The zero indexed redirect hop. Defaults to the final hop.function expectHeader($key, $value [, $hop = null])
Verify that a header field equals an expected value.
$key
- The header field name to verify.$value
- The expected value.null | int $hop - The zero indexed redirect hop. Defaults to the final hop. |
function expectHeaderContains($key, $value [, $hop = null])
Verify that a header field contains an expected value.
For example, checking the header Content-Type for “json” would match a response of “application/json”
$key
- The header field name to verify.$value
- The expected containing value.null | int $hop - The zero indexed redirect hop. Defaults to the final hop. |
function expectBody($expectedContent)
Verify that the content body equals an expected value.
$expectedContent
- The expected value.function expectBodyContains($expectedContent)
Verify that the content body contains an expected value.
$expectedContent
- The expected containing value.function expectHopCount($expectedCount)
Verify the number of redirection hops is as expected.
$expectedCount
- The expected number of redirect hops.