Boomerang Application
function addValidator(\Boomerang\Interfaces\ValidatorInterface $validator)
Register a Validator with Boomerang
After creating an instance of a Validator, it needs to be registered with Boomerang in order for results to be
tallied and displayed.
$validator
Utility for generating HTTP Requests and receiving Responses into HttpResponse
objects.
<?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 getMethod()
Get the current request method.
function setMethod($method)
Set the request method.
$req->setMethod(HttpRequest::POST);
$method
function getUrlParam($param)
Retrieve a url param by name
$param
- The name of the param.string | array | null - Null on failure. |
function setUrlParam($param, $value)
Set a url param by name.
$param
- The name of the param.string | int | float | array $value |
function getUrlParams()
Get all url params.
function setUrlParams(array $params)
Set outgoing params as an array of ParamName => Value
$params
- Params to setfunction getHeader($key)
Retrieve an outgoing header by name
$key
- The name of the header.string | null - Null on failure. |
function setHeader($key, $value)
Set an outgoing header by name.
$key
- The name of the header.$value
- The value to set the header to.function getHeaders()
Get all set headers.
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 getPost($key)
Retrieve an post value by name.
Use getFormValue instead
$key
string | null |
function setPost($key, $value)
Set a named key of the post value
Note that this has the side effect of changing the HTTP Method to POST
Use setMethod and setFormValue instead
$key
$value
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 getFormValue($key)
Retrieve an form value by name.
$key
mixed | null |
function getPostData()
Retrieve all queued post-data as an array.
Use getBody instead
array | string |
function setPostData(array $post)
Set all post data, whipping past values.
Note that this has the side effect of changing the HTTP Method to POST
Use setBody instead
$post
function getBody()
Get the requests body
array | string |
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 getEndpoint()
Gets the request URI
function setEndpoint($endpoint)
Sets the request URI
$endpoint
function makeRequest()
Execute the request
function getCurlInfo()
function getLastRequestTime()
Get the time the last request took in seconds a float
null | float - null if there is no last request |
function getMaxRedirects()
Get the current maximum number of redirects(hops) a request should follow.
function setMaxRedirects($maxRedirects)
Set the maximum number of redirects(hops) a request should follow.
$maxRedirects
Represents an HTTP Response.
Usually received from an HttpRequest
object
function __construct($body, $headers [, \Boomerang\HttpRequest $request = null])
$body
- The body of the HTTP Request$headers
\Boomerang\HttpRequest | null $request |
function getHeader($header [, $hop = null])
Get a response header by name.
$header
null | int $hop |
null | string - Header value or null on not found |
function getHeaders([ $hop = null])
Get response headers as a HeaderName => Value array
null | int $hop - The zero indexed hop(redirect). Defaults to the final hop. |
array | null |
function getAllHeaders()
Get all response headers from all hops as a HopIndex => HeaderName => Value array.
Note: header key values are lower cased.
function getRawHeaders()
Get the raw un-parsed Response header string.
function getBody()
Get the body of the Response.
function getRequest()
Get the HttpRequest object that made the Response object.
function getHopCount()
Get the number of hops(redirects) the request took
function getStatus([ $hop = null])
Get the HTTP status of a hop
int | null $hop - The zero indexed hop(redirect). Defaults to the final hop. |
int | null |
HTTP Validation
Used to validate expected responses, headers and HTTP statues
function __construct(\Boomerang\Interfaces\HttpResponseInterface $response)
$response
function getResponse()
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.JSON Validator
Used to validate JSON encoding and structure.
function __construct(\Boomerang\Interfaces\ResponseInterface $response)
$response
- The response to inspectfunction inspectJSON()
Log the JSON response as an InfoResult in the output.
All Expectation
Defines a requirement to match all structure definitions expectations.
Example:
new AllEx(
array(1,2,3),
function($data) { return count($data) == 3; }
);
function __construct($structure)
\Boomerang\Interfaces\TypeExpectationInterface | callable | mixed $structure,... - One or more structure definitions to match |
AllEx->match($data)
AllEx->getMatchingTypeName()
Any Expectation
Defines a requirement to match any structure definitions expectations.
Example:
new AllEx(
array(1,2,3),
function($data) { return count($data) == 4; }
);
AnyEx->match($data)
AnyEx->getMatchingTypeName()
Integer Expectation
Defines a placeholder expectation of an integer with an optional minimum/maximum range.
Passes: int Fails: float/numeric string
IntEx->match($data)
IntEx->getMatchingTypeName()
Iterating Array Expectation
Iterates over every element of an array, ensuring it is an array, and matching against passed structure expectations.
IterateArrayEx->match($data)
IterateArrayEx->getMatchingTypeName()
Iterating Object Expectation
Iterates over every element of an object, ensuring it is an object, and matching against passed structure expectations.
IterateObjectEx->getMatchingTypeName()
Iterating Structure (object/array) Expectation
Iterates over every element of a iterable structure (object/array), ensuring it iterable, and matching against passed structure expectations.
IterateStructureEx->match($data)
IterateStructureEx->getMatchingTypeName()
Null Expectation
Defines a placeholder expectation of a NULL value.
Passes: null
NullEx->match($data)
NullEx->getMatchingTypeName()
Number Expectation
Defines a placeholder expectation of a “number” (int/float) with an optional minimum/maximum range.
Passes: int
/ float
Fails: numeric string
NumberEx->match($data)
NumberEx->getMatchingTypeName()
Numeric Expectation
Defines a placeholder expectation of a “numeric” (int/float/numeric string) with an optional minimum/maximum range.
See: php.net/is_numeric
Passes: numeric string
/ int
/ float
function __construct([ $min = null [, $max = null]])
null | int | float $min - Optional minimum valid value |
null | int | float $max - Optional maximum valid value |
NumericEx->match($data)
NumericEx->getMatchingTypeName()
Numeric String Expectation
Defines a placeholder expectation of a “numeric string” with an optional minimum/maximum range.
Passes: numeric string
eg: “1.2”
Fails: int
/ float
NumericStringEx->match($data)
NumericStringEx->getMatchingTypeName()
Regex Match Expectation
Define a regex matching placeholder
function __construct($pattern)
$pattern
- The preg pattern to search forRegexEx->match($data)
RegexEx->getMatchingTypeName()
String Expectation
Define a string matching placeholder expectation
function __construct([ $minLength = null [, $maxLength = null]])
null | int $minLength - Optional minimum length in bytes of a valid value |
null | int $maxLength - Optional maximum length in bytes of a valid value |
StringEx->match($data)
StringEx->getMatchingTypeName()
Structure Expectation
Used to define rules about structure.
function __construct($structure)
\Boomerang\Interfaces\TypeExpectationInterface | callable | mixed $structure |
function getValidator()
StructureEx->getMatchingTypeName()