+
+
+
+ __construct()
+
+
+
+
+ PockBuilder constructor.
+
+
+ public
+ __construct() : mixed
+
+
+
+
+
+ Return values
+ mixed
+ —
+
+
+
+
+
+ addMatcher()
+
+
+
+
+ Add custom matcher to the mock.
+
+
+ public
+ addMatcher(RequestMatcherInterface $matcher) : self
+
+
+ Parameters
+
+ -
+ $matcher
+ : RequestMatcherInterface
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ always()
+
+
+
+
+ Always execute this mock if matched. Mock with this call will not be expired ever.
+
+
+ public
+ always() : self
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ at()
+
+
+
+
+ Match request only at Nth hit. Previous matches will not be executed.
+
+
+ public
+ at(int $hit) : self
+
+ Note: There IS a catch if you use this with the equal mocks. The test Client will not register hit
+for the second mock and the second mock will be executed at N+1 time.
+For example, if you try to send 5 requests with this mocks and log response codes:
+$builder = new PockBuilder();
+
+$builder->matchHost('example.com')->at(2)->reply(200);
+$builder->matchHost('example.com')->at(4)->reply(201);
+$builder->always()->reply(400);
+
+You will get this: 400, 400, 200, 400, 400, 201
+Instead of this: 400, 400, 200, 400, 201, 400
+
+
+ Parameters
+
+ -
+ $hit
+ : int
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ getClient()
+
+
+
+
+
+
+ public
+ getClient() : Client
+
+
+
+
+
+ Return values
+ Client
+ —
+
+
+
+
+
+ jsonDecode()
+
+
+
+
+ json_decode which throws exception on error.
+
+
+ public
+ static jsonDecode(string $json[, bool $associative = false ][, int $depth = 512 ], int $flags) : mixed
+
+
+ Parameters
+
+ -
+ $json
+ : string
+
+ -
+
+
+ -
+ $associative
+ : bool
+ = false
+ -
+
+
+ -
+ $depth
+ : int
+ = 512
+ -
+
+
+ -
+ $flags
+ : int
+
+ -
+
+
+
+
+
+
+
+ -
+ throws
+
+ -
+ JsonException
+
+
+
+ -
+ SuppressWarnings
+
+ -
+
+
(PHPMD.BooleanArgumentFlag)
+
+
+
+
+
+ Return values
+ mixed
+ —
+
+
+
+
+
+ matchBody()
+
+
+
+
+ Match entire request body.
+
+
+ public
+ matchBody(StreamInterface|resource|string $data) : self
+
+
+ Parameters
+
+ -
+ $data
+ : StreamInterface|resource|string
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchBodyRegExp()
+
+
+
+
+ Match entire request body using provided regular expression.
+
+
+ public
+ matchBodyRegExp(string $expression, int $flags) : self
+
+
+ Parameters
+
+ -
+ $expression
+ : string
+
+ -
+
+
+ -
+ $flags
+ : int
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchCallback()
+
+
+
+
+ Match request using provided callback. Callback should receive RequestInterface and return boolean.
+
+
+ public
+ matchCallback(callable $callback) : self
+
+ If returned value is true then request is matched.
+
+
+ Parameters
+
+ -
+ $callback
+ : callable
+
+ -
+
Callable that accepts PSR-7 RequestInterface as it's first argument.
+
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+
+
+ Match request with form-data. Additional fields aren't allowed.
+
+
+ public
+ matchExactFormData(array<string, mixed> $formFields) : self
+
+
+ Parameters
+
+ -
+ $formFields
+ : array<string, mixed>
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+
+
+ Matches request by the exact header pattern or values.
+
+
+ public
+ matchExactHeader(string $header, string|array<string|int, string> $value) : self
+
+
+ Parameters
+
+ -
+ $header
+ : string
+
+ -
+
+
+ -
+ $value
+ : string|array<string|int, string>
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+
+
+ Matches request by headers values or several values.
+
+
+ public
+ matchExactHeaders(array<string, string|string[]> $headers) : self
+
+ Note: only host header will be dropped. Any other headers will not be excluded and can result in the problems
+with the exact matching.
+
+
+ Parameters
+
+ -
+ $headers
+ : array<string, string|string[]>
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchExactQuery()
+
+
+
+
+ Match request by its query. Additional query parameters aren't allowed.
+
+
+ public
+ matchExactQuery(array<string, mixed> $query) : self
+
+
+ Parameters
+
+ -
+ $query
+ : array<string, mixed>
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+
+
+ Match request with form-data.
+
+
+ public
+ matchFormData(array<string, mixed> $formFields) : self
+
+
+ Parameters
+
+ -
+ $formFields
+ : array<string, mixed>
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+
+
+ Matches request by header value or several values. Header can have other values which are not specified here.
+
+
+ public
+ matchHeader(string $header, string|array<string|int, string> $value) : self
+
+
+ Parameters
+
+ -
+ $header
+ : string
+
+ -
+
+
+ -
+ $value
+ : string|array<string|int, string>
+
+ -
+
+
+
+
+
+
+
+ -
+ see
+
+ -
+ PockBuilder::matchExactHeader()
+
+
if you want to match exact header values.
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+
+
+ Matches request by the unparsed header line.
+
+
+ public
+ matchHeaderLine(string $header, string $value) : self
+
+
+ Parameters
+
+ -
+ $header
+ : string
+
+ -
+
+
+ -
+ $value
+ : string
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+
+
+ Matches request by the unparsed header line using provided regular expression.
+
+
+ public
+ matchHeaderLineRegexp(string $header, string $pattern) : self
+
+
+ Parameters
+
+ -
+ $header
+ : string
+
+ -
+
+
+ -
+ $pattern
+ : string
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+
+
+ Matches request by headers values or several values. Headers can have other values which are not specified here.
+
+
+ public
+ matchHeaders(array<string, string|string[]> $headers) : self
+
+
+ Parameters
+
+ -
+ $headers
+ : array<string, string|string[]>
+
+ -
+
+
+
+
+
+
+
+ -
+ see
+
+ -
+ PockBuilder::matchExactHeaders()
+
+
if you want to match exact headers collection.
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchHost()
+
+
+
+
+ Matches request by hostname.
+
+
+ public
+ matchHost(string $host) : self
+
+
+ Parameters
+
+ -
+ $host
+ : string
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchJsonBody()
+
+
+
+
+ Match JSON request body.
+
+
+ public
+ matchJsonBody(mixed $data) : self
+
+
+ Parameters
+
+ -
+ $data
+ : mixed
+
+ -
+
+
+
+
+
+
+
+ -
+ throws
+
+ -
+ JsonException
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchMethod()
+
+
+
+
+ Match request by its method.
+
+
+ public
+ matchMethod(string $method) : self
+
+
+ Parameters
+
+ -
+ $method
+ : string
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+
+
+ Match request multipart form data. Will not match the request if body is not multipart.
+
+
+ public
+ matchMultipartFormData(callable $callback) : self
+
+ Uses third-party library to parse the data.
+
+
+ Parameters
+
+ -
+ $callback
+ : callable
+
+ -
+
Accepts Riverline\MultiPartParser\StreamedPart as an argument, returns true if matched.
+
+
+
+
+
+
+
+
+ -
+ see
+
+ -
+ https://github.com/Riverline/multipart-parser#usage
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchOrigin()
+
+
+
+
+ Matches request by origin.
+
+
+ public
+ matchOrigin(string $origin) : self
+
+
+ Parameters
+
+ -
+ $origin
+ : string
+
+ -
+
+
+
+
+
+
+
+ -
+ throws
+
+ -
+ RuntimeException
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchPath()
+
+
+
+
+ Match request by its path. Path with and without slash at the start will be treated as the same path.
+
+
+ public
+ matchPath(string $path) : self
+
+ It's not the same for the path with slash at the end of it.
+
+
+ Parameters
+
+ -
+ $path
+ : string
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchPathRegExp()
+
+
+
+
+ Match request by its path using regular expression. This matcher doesn't care about prefix slash
+since it's pretty easy to do it using regular expression.
+
+
+ public
+ matchPathRegExp(string $expression, int $flags) : self
+
+
+ Parameters
+
+ -
+ $expression
+ : string
+
+ -
+
+
+ -
+ $flags
+ : int
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchPort()
+
+
+
+
+ Matches request by the port.
+
+
+ public
+ matchPort(int $port) : self
+
+
+ Parameters
+
+ -
+ $port
+ : int
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchQuery()
+
+
+
+
+ Match request by its query. Request can contain other query variables.
+
+
+ public
+ matchQuery(array<string, mixed> $query) : self
+
+
+ Parameters
+
+ -
+ $query
+ : array<string, mixed>
+
+ -
+
+
+
+
+
+
+
+ -
+ see
+
+ -
+ PockBuilder::matchExactQuery()
+
+
if you want to match an entire query string.
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchQueryRegExp()
+
+
+
+
+ Match request by its query using regular expression.
+
+
+ public
+ matchQueryRegExp(string $expression, int $flags) : self
+
+
+ Parameters
+
+ -
+ $expression
+ : string
+
+ -
+
+
+ -
+ $flags
+ : int
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchScheme()
+
+
+
+
+ Match request by its scheme.
+
+
+ public
+ matchScheme(string $scheme) : self
+
+
+ Parameters
+
+ -
+ $scheme
+ : string
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchSerializedJsonBody()
+
+
+
+
+ Match JSON request body against JSON string or array with data.
+
+
+ public
+ matchSerializedJsonBody(array<int|string, mixed>|string $data) : self
+
+
+ Parameters
+
+ -
+ $data
+ : array<int|string, mixed>|string
+
+ -
+
+
+
+
+
+
+
+ -
+ throws
+
+ -
+ JsonException
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchSerializedXmlBody()
+
+
+
+
+ Match XML request body.
+
+
+ public
+ matchSerializedXmlBody(string|array<string|int, mixed>|object $data) : self
+
+ This method will try to use available XML serializer before matching.
+
+
+ Parameters
+
+ -
+ $data
+ : string|array<string|int, mixed>|object
+
+ -
+
+
+
+
+
+
+
+ -
+ phpstan-ignore-next-line
+
+ -
+
+
+
+ -
+ throws
+
+ -
+ XmlException
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchUri()
+
+
+
+
+ Matches request by the whole URI.
+
+
+ public
+ matchUri(UriInterface|string $uri) : self
+
+
+ Parameters
+
+ -
+ $uri
+ : UriInterface|string
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchUriRegExp()
+
+
+
+
+ Matches request by the whole URI using regular expression.
+
+
+ public
+ matchUriRegExp(string $expression, int $flags) : self
+
+
+ Parameters
+
+ -
+ $expression
+ : string
+
+ -
+
+
+ -
+ $flags
+ : int
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ matchXmlBody()
+
+
+
+
+ Match XML request body using raw XML data.
+
+
+ public
+ matchXmlBody(DOMDocument|StreamInterface|resource|string $data) : self
+
+ Note: this method will fallback to the string comparison if ext-xsl is not available.
+It also doesn't serializer values with available XML serializer.
+Use PockBuilder::matchSerializedXmlBody if you want to execute available serializer.
+
+
+ Parameters
+
+ -
+ $data
+ : DOMDocument|StreamInterface|resource|string
+
+ -
+
+
+
+
+
+
+
+ -
+ throws
+
+ -
+ XmlException
+
+
+
+ -
+ see
+
+ -
+ PockBuilder::matchSerializedXmlBody()
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ repeat()
+
+
+
+
+ Repeat this mock provided amount of times.
+
+
+ public
+ repeat(int $hits) : self
+
+ For example, if you pass 2 as an argument mock will be able to handle two identical requests.
+
+
+ Parameters
+
+ -
+ $hits
+ : int
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ reply()
+
+
+
+
+
+
+ public
+ reply([int $statusCode = 200 ]) : PockResponseBuilder
+
+
+ Parameters
+
+ -
+ $statusCode
+ : int
+ = 200
+ -
+
+
+
+
+
+
+ Return values
+ PockResponseBuilder
+ —
+
+
+
+
+
+ replyWithCallback()
+
+
+
+
+ Construct the response during request execution using provided callback.
+
+
+ public
+ replyWithCallback(callable $callback) : void
+
+ Callback should receive the same parameters as in the ReplyFactoryInterface::createReply
method.
+
+
+ Parameters
+
+ -
+ $callback
+ : callable
+
+ -
+
+
+
+
+
+
+
+ -
+ see
+
+ -
+ ReplyFactoryInterface::createReply()
+
+
+
+
+
+ Return values
+ void
+ —
+
+
+
+
+
+ replyWithClient()
+
+
+
+
+ Reply to the request using provided client. Can be used to send real network request.
+
+
+ public
+ replyWithClient(ClientInterface $client) : void
+
+
+ Parameters
+
+ -
+ $client
+ : ClientInterface
+
+ -
+
+
+
+
+
+
+
+ -
+ SuppressWarnings
+
+ -
+
+
+
+
+
+
+ Return values
+ void
+ —
+
+
+
+
+
+ replyWithFactory()
+
+
+
+
+ Construct the response during request execution using provided ReplytFactoryInterface implementation.
+
+
+ public
+ replyWithFactory(ReplyFactoryInterface $factory) : void
+
+
+ Parameters
+
+ -
+ $factory
+ : ReplyFactoryInterface
+
+ -
+
+
+
+
+
+
+
+ -
+ see
+
+ -
+ ReplyFactoryInterface
+
+
+
+
+
+ Return values
+ void
+ —
+
+
+
+
+
+ reset()
+
+
+
+
+ Resets the builder.
+
+
+ public
+ reset() : self
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ setFallbackClient()
+
+
+
+
+ Sets fallback Client. It will be used if no request can be matched.
+
+
+ public
+ setFallbackClient([ClientInterface|null $fallbackClient = null ]) : self
+
+
+ Parameters
+
+ -
+ $fallbackClient
+ : ClientInterface|null
+ = null
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ throwClientException()
+
+
+
+
+ Throw an ClientExceptionInterface instance with specified message
+
+
+ public
+ throwClientException([string $message = 'Pock ClientException' ]) : self
+
+
+ Parameters
+
+ -
+ $message
+ : string
+ = 'Pock ClientException'
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ throwException()
+
+
+
+
+ Throw an exception when request is being sent.
+
+
+ public
+ throwException(Throwable $throwable) : self
+
+
+ Parameters
+
+ -
+ $throwable
+ : Throwable
+
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ throwNetworkException()
+
+
+
+
+ Throw an NetworkExceptionInterface instance with specified message
+
+
+ public
+ throwNetworkException([string $message = 'Pock NetworkException' ]) : self
+
+
+ Parameters
+
+ -
+ $message
+ : string
+ = 'Pock NetworkException'
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+ throwRequestException()
+
+
+
+
+ Throw an RequestExceptionInterface instance with specified message
+
+
+ public
+ throwRequestException([string $message = 'Pock RequestException' ]) : self
+
+
+ Parameters
+
+ -
+ $message
+ : string
+ = 'Pock RequestException'
+ -
+
+
+
+
+
+
+ Return values
+ self
+ —
+
+
+
+
+
+
+
+
+