HumHub Documentation (unofficial)

TestClient extends Client
in package

Client simulates a browser.

To make the actual request, you need to implement the doRequest() method.

If you want to be able to run requests in their own process (insulated flag), you need to also implement the getScript() method.

Table of Contents

Properties

$cookieJar  : mixed
$crawler  : mixed
$followRedirects  : mixed
$history  : mixed
$insulated  : mixed
$internalRequest  : mixed
$internalResponse  : mixed
$nextResponse  : mixed
$nextScript  : mixed
$redirect  : mixed
$request  : mixed
$response  : mixed
$server  : mixed
$isMainRequest  : mixed
$maxRedirects  : mixed
$redirectCount  : mixed
$redirects  : mixed

Methods

__construct()  : mixed
back()  : Crawler
Goes back in the browser history.
click()  : Crawler
Clicks on a given link.
followRedirect()  : Crawler
Follow redirects?
followRedirects()  : mixed
Sets whether to automatically follow redirects or not.
forward()  : Crawler
Goes forward in the browser history.
getCookieJar()  : CookieJar
Returns the CookieJar instance.
getCrawler()  : Crawler|null
Returns the current Crawler instance.
getHistory()  : History
Returns the History instance.
getInternalRequest()  : Request|null
Returns the current BrowserKit Request instance.
getInternalResponse()  : Response|null
Returns the current BrowserKit Response instance.
getMaxRedirects()  : int
Returns the maximum number of redirects that crawler can follow.
getRequest()  : object|null
Returns the current origin Request instance.
getResponse()  : object|null
Returns the current origin response instance.
getServerParameter()  : mixed
Gets single server parameter for specified key.
insulate()  : mixed
Sets the insulated flag.
isFollowingRedirects()  : bool
Returns whether client automatically follows redirects or not.
reload()  : Crawler
Reloads the current browser.
request()  : Crawler
Calls a URI.
restart()  : mixed
Restarts the client.
setMaxRedirects()  : mixed
Sets the maximum number of redirects that crawler can follow.
setNextResponse()  : mixed
setNextScript()  : mixed
setServerParameter()  : mixed
Sets single server parameter.
setServerParameters()  : mixed
Sets server parameters.
submit()  : Crawler
Submits a form.
createCrawlerFromContent()  : Crawler|null
Creates a crawler.
doRequest()  : object
Makes a request.
doRequestInProcess()  : object
Makes a request in another process.
filterRequest()  : object
Filters the BrowserKit request to the origin one.
filterResponse()  : Response
Filters the origin response to the BrowserKit one.
getAbsoluteUri()  : string
Takes a URI and converts it to absolute if it is not already absolute.
getScript()  : mixed
Returns the script to execute when the request must be insulated.
requestFromRequest()  : Crawler
Makes a request from a Request object directly.
extractHost()  : mixed
updateServerFromUri()  : mixed

Properties

$cookieJar

protected mixed $cookieJar

$crawler

protected mixed $crawler

$followRedirects

protected mixed $followRedirects = true

$history

protected mixed $history

$insulated

protected mixed $insulated = false

$internalRequest

protected mixed $internalRequest

$internalResponse

protected mixed $internalResponse

$nextResponse

protected mixed $nextResponse = null

$redirect

protected mixed $redirect

$request

protected mixed $request

$response

protected mixed $response

$server

protected mixed $server = []

$isMainRequest

private mixed $isMainRequest = true

$maxRedirects

private mixed $maxRedirects = -1

$redirectCount

private mixed $redirectCount = 0

$redirects

private mixed $redirects = []

Methods

__construct()

public __construct([array<string|int, mixed> $server = [] ][, History $history = null ][, CookieJar $cookieJar = null ]) : mixed
Parameters
$server : array<string|int, mixed> = []

The server parameters (equivalent of $_SERVER)

$history : History = null

A History instance to store the browser history

$cookieJar : CookieJar = null

A CookieJar instance to store the cookies

followRedirect()

Follow redirects?

public followRedirect() : Crawler
Tags
throws
LogicException

If request was not a redirect

Return values
Crawler

followRedirects()

Sets whether to automatically follow redirects or not.

public followRedirects([bool $followRedirect = true ]) : mixed
Parameters
$followRedirect : bool = true

Whether to follow redirects

getCookieJar()

Returns the CookieJar instance.

public getCookieJar() : CookieJar
Return values
CookieJar

A CookieJar instance

getCrawler()

Returns the current Crawler instance.

public getCrawler() : Crawler|null
Return values
Crawler|null

A Crawler instance

getHistory()

Returns the History instance.

public getHistory() : History
Return values
History

A History instance

getInternalRequest()

Returns the current BrowserKit Request instance.

public getInternalRequest() : Request|null
Return values
Request|null

A BrowserKit Request instance

getInternalResponse()

Returns the current BrowserKit Response instance.

public getInternalResponse() : Response|null
Return values
Response|null

A BrowserKit Response instance

getMaxRedirects()

Returns the maximum number of redirects that crawler can follow.

public getMaxRedirects() : int
Return values
int

getRequest()

Returns the current origin Request instance.

public getRequest() : object|null

The origin request is the request instance that is sent to the code that handles requests.

Tags
see
doRequest()
Return values
object|null

A Request instance

getResponse()

Returns the current origin response instance.

public getResponse() : object|null

The origin response is the response instance that is returned by the code that handles requests.

Tags
see
doRequest()
Return values
object|null

A response instance

getServerParameter()

Gets single server parameter for specified key.

public getServerParameter(string $key[, mixed $default = '' ]) : mixed
Parameters
$key : string

A key of the parameter to get

$default : mixed = ''

A default value when key is undefined

Return values
mixed

A value of the parameter

insulate()

Sets the insulated flag.

public insulate([bool $insulated = true ]) : mixed
Parameters
$insulated : bool = true

Whether to insulate the requests or not

Tags
throws
RuntimeException

When Symfony Process Component is not installed

isFollowingRedirects()

Returns whether client automatically follows redirects or not.

public isFollowingRedirects() : bool
Return values
bool

request()

Calls a URI.

public request(string $method, string $uri[, array<string|int, mixed> $parameters = [] ][, array<string|int, mixed> $files = [] ][, array<string|int, mixed> $server = [] ][, string $content = null ][, bool $changeHistory = true ]) : Crawler
Parameters
$method : string

The request method

$uri : string

The URI to fetch

$parameters : array<string|int, mixed> = []

The Request parameters

$files : array<string|int, mixed> = []

The files

$server : array<string|int, mixed> = []

The server parameters (HTTP headers are referenced with a HTTP_ prefix as PHP does)

$content : string = null

The raw body data

$changeHistory : bool = true

Whether to update the history or not (only used internally for back(), forward(), and reload())

Return values
Crawler

restart()

Restarts the client.

public restart() : mixed

It flushes history and all cookies.

setMaxRedirects()

Sets the maximum number of redirects that crawler can follow.

public setMaxRedirects(int $maxRedirects) : mixed
Parameters
$maxRedirects : int

setNextScript()

public setNextScript(mixed $script) : mixed
Parameters
$script : mixed

setServerParameter()

Sets single server parameter.

public setServerParameter(string $key, string $value) : mixed
Parameters
$key : string

A key of the parameter

$value : string

A value of the parameter

setServerParameters()

Sets server parameters.

public setServerParameters(array<string|int, mixed> $server) : mixed
Parameters
$server : array<string|int, mixed>

An array of server parameters

submit()

Submits a form.

public submit(Form $form[, array<string|int, mixed> $values = [] ]) : Crawler
Parameters
$form : Form

A Form instance

$values : array<string|int, mixed> = []

An array of form field values

Return values
Crawler

createCrawlerFromContent()

Creates a crawler.

protected createCrawlerFromContent(string $uri, string $content, string $type) : Crawler|null

This method returns null if the DomCrawler component is not available.

Parameters
$uri : string

A URI

$content : string

Content for the crawler to use

$type : string

Content type

Return values
Crawler|null

doRequest()

Makes a request.

protected doRequest(mixed $request) : object
Parameters
$request : mixed

An origin request instance

Return values
object

An origin response instance

doRequestInProcess()

Makes a request in another process.

protected doRequestInProcess(object $request) : object
Parameters
$request : object

An origin request instance

Tags
throws
RuntimeException

When processing returns exit code

Return values
object

An origin response instance

filterRequest()

Filters the BrowserKit request to the origin one.

protected filterRequest(Request $request) : object
Parameters
$request : Request

The BrowserKit Request to filter

Return values
object

An origin request instance

filterResponse()

Filters the origin response to the BrowserKit one.

protected filterResponse(mixed $response) : Response
Parameters
$response : mixed

The origin response to filter

Return values
Response

An BrowserKit Response instance

getAbsoluteUri()

Takes a URI and converts it to absolute if it is not already absolute.

protected getAbsoluteUri(string $uri) : string
Parameters
$uri : string

A URI

Return values
string

An absolute URI

getScript()

Returns the script to execute when the request must be insulated.

protected getScript(mixed $request) : mixed
Parameters
$request : mixed

An origin request instance

requestFromRequest()

Makes a request from a Request object directly.

protected requestFromRequest(Request $request[, bool $changeHistory = true ]) : Crawler
Parameters
$request : Request

A Request instance

$changeHistory : bool = true

Whether to update the history or not (only used internally for back(), forward(), and reload())

Return values
Crawler

extractHost()

private extractHost(mixed $uri) : mixed
Parameters
$uri : mixed

updateServerFromUri()

private updateServerFromUri(mixed $server, mixed $uri) : mixed
Parameters
$server : mixed
$uri : mixed

        
On this page

Search results