class Client extends Client

Client simulates a browser and makes requests to a Kernel object.

Properties

protected $history from Client
protected $cookieJar from Client
protected $server from Client
protected $internalRequest from Client
protected $request from Client
protected $internalResponse from Client
protected $response from Client
protected $crawler from Client
protected $insulated from Client
protected $redirect from Client
protected $followRedirects from Client
protected $followMetaRefresh from Client
protected $kernel

Methods

__construct(HttpKernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null)

No description

followRedirects(bool $followRedirect = true)

Sets whether to automatically follow redirects or not.

from Client
followMetaRefresh(bool $followMetaRefresh = true)

Sets whether to automatically follow meta refresh redirects or not.

from Client
bool
isFollowingRedirects()

Returns whether client automatically follows redirects or not.

from Client
setMaxRedirects(int $maxRedirects)

Sets the maximum number of redirects that crawler can follow.

from Client
int
getMaxRedirects()

Returns the maximum number of redirects that crawler can follow.

from Client
insulate(bool $insulated = true)

Sets the insulated flag.

from Client
setServerParameters(array $server)

Sets server parameters.

from Client
setServerParameter(string $key, string $value)

Sets single server parameter.

from Client
string
getServerParameter(string $key, string $default = '')

Gets single server parameter for specified key.

from Client
xmlHttpRequest(string $method, string $uri, array $parameters = array(), array $files = array(), array $server = array(), string $content = null, bool $changeHistory = true)

No description

from Client
getHistory()

Returns the History instance.

from Client
getCookieJar()

Returns the CookieJar instance.

from Client
getCrawler()

Returns the current Crawler instance.

from Client
getInternalResponse()

Returns the current BrowserKit Response instance.

from Client
Response
getResponse()

A Response instance

getInternalRequest()

Returns the current BrowserKit Request instance.

from Client
Request
getRequest()

A Request instance

click(Link $link)

Clicks on a given link.

from Client
clickLink(string $linkText)

Clicks the first link (or clickable image) that contains the given text.

from Client
submit(Form $form, array $values = array())

Submits a form.

from Client
submitForm(string $button, array $fieldValues = array(), string $method = 'POST', array $serverParameters = array())

Finds the first form that contains a button with the given content and uses it to submit the given form field values.

from Client
request(string $method, string $uri, array $parameters = array(), array $files = array(), array $server = array(), string $content = null, bool $changeHistory = true)

Calls a URI.

from Client
object
doRequestInProcess(object $request)

Makes a request in another process.

from Client
object
doRequest(object $request)

Makes a request.

getScript(object $request)

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

object
filterRequest(Request $request)

Converts the BrowserKit request to a HttpKernel request.

filterResponse(object $response)

Converts the HttpKernel response to a BrowserKit response.

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

Creates a crawler.

from Client
back()

Goes back in the browser history.

from Client
forward()

Goes forward in the browser history.

from Client
reload()

Reloads the current browser.

from Client
followRedirect()

Follow redirects?

from Client
restart()

Restarts the client.

from Client
string
getAbsoluteUri(string $uri)

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

from Client
requestFromRequest(Request $request, bool $changeHistory = true)

Makes a request from a Request object directly.

from Client
catchExceptions(bool $catchExceptions)

Sets whether to catch exceptions when the kernel is handling a request.

getHandleScript()

No description

array
filterFiles(array $files)

Filters an array of files.

Details

at line 42
__construct(HttpKernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null)

Parameters

HttpKernelInterface $kernel An HttpKernel instance
array $server The server parameters (equivalent of $_SERVER)
History $history A History instance to store the browser history
CookieJar $cookieJar A CookieJar instance to store the cookies

in Client at line 67
followRedirects(bool $followRedirect = true)

Sets whether to automatically follow redirects or not.

Parameters

bool $followRedirect Whether to follow redirects

in Client at line 75
followMetaRefresh(bool $followMetaRefresh = true)

Sets whether to automatically follow meta refresh redirects or not.

Parameters

bool $followMetaRefresh

in Client at line 85
bool isFollowingRedirects()

Returns whether client automatically follows redirects or not.

Return Value

bool

in Client at line 95
setMaxRedirects(int $maxRedirects)

Sets the maximum number of redirects that crawler can follow.

Parameters

int $maxRedirects

in Client at line 106
int getMaxRedirects()

Returns the maximum number of redirects that crawler can follow.

Return Value

int

in Client at line 118
insulate(bool $insulated = true)

Sets the insulated flag.

Parameters

bool $insulated Whether to insulate the requests or not

Exceptions

RuntimeException When Symfony Process Component is not installed

in Client at line 132
setServerParameters(array $server)

Sets server parameters.

Parameters

array $server An array of server parameters

in Client at line 145
setServerParameter(string $key, string $value)

Sets single server parameter.

Parameters

string $key A key of the parameter
string $value A value of the parameter

in Client at line 158
string getServerParameter(string $key, string $default = '')

Gets single server parameter for specified key.

Parameters

string $key A key of the parameter to get
string $default A default value when key is undefined

Return Value

string A value of the parameter

in Client at line 163
Crawler xmlHttpRequest(string $method, string $uri, array $parameters = array(), array $files = array(), array $server = array(), string $content = null, bool $changeHistory = true)

Parameters

string $method
string $uri
array $parameters
array $files
array $server
string $content
bool $changeHistory

Return Value

Crawler

in Client at line 179
History getHistory()

Returns the History instance.

Return Value

History A History instance

in Client at line 189
CookieJar getCookieJar()

Returns the CookieJar instance.

Return Value

CookieJar A CookieJar instance

in Client at line 199
Crawler getCrawler()

Returns the current Crawler instance.

Return Value

Crawler A Crawler instance

in Client at line 214
Response getInternalResponse()

Returns the current BrowserKit Response instance.

Return Value

Response A BrowserKit Response instance

at line 31
Response getResponse()

A Response instance

Return Value

Response

in Client at line 249
Request getInternalRequest()

Returns the current BrowserKit Request instance.

Return Value

Request A BrowserKit Request instance

at line 31
Request getRequest()

A Request instance

Return Value

Request

in Client at line 284
Crawler click(Link $link)

Clicks on a given link.

Parameters

Link $link

Return Value

Crawler

Clicks the first link (or clickable image) that contains the given text.

Parameters

string $linkText The text of the link or the alt attribute of the clickable image

Return Value

Crawler

in Client at line 316
Crawler submit(Form $form, array $values = array())

Submits a form.

Parameters

Form $form
array $values

Return Value

Crawler

in Client at line 337
Crawler submitForm(string $button, array $fieldValues = array(), string $method = 'POST', array $serverParameters = array())

Finds the first form that contains a button with the given content and uses it to submit the given form field values.

Parameters

string $button The text content, id, value or name of the form
array $fieldValues Use this syntax: array('my_form[name]' => '...', 'my_form[email]' => '...')
string $method The HTTP method used to submit the form
array $serverParameters These values override the ones stored in $SERVER (HTTP headers must include a HTTP prefix as PHP does)

Return Value

Crawler

in Client at line 362
Crawler request(string $method, string $uri, array $parameters = array(), array $files = array(), array $server = array(), string $content = null, bool $changeHistory = true)

Calls a URI.

Parameters

string $method The request method
string $uri The URI to fetch
array $parameters The Request parameters
array $files The files
array $server The server parameters (HTTP headers are referenced with a HTTP_ prefix as PHP does)
string $content The raw body data
bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())

Return Value

Crawler

in Client at line 447
protected object doRequestInProcess(object $request)

Makes a request in another process.

Parameters

object $request An origin request instance

Return Value

object An origin response instance

Exceptions

RuntimeException When processing returns exit code

at line 66
protected object doRequest(object $request)

Makes a request.

Parameters

object $request An origin request instance

Return Value

object An origin response instance

at line 82
protected getScript(object $request)

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

Parameters

object $request An origin request instance

at line 136
protected object filterRequest(Request $request)

Converts the BrowserKit request to a HttpKernel request.

Parameters

Request $request The BrowserKit Request to filter

Return Value

object An origin request instance

at line 195
protected Response filterResponse(object $response)

Converts the HttpKernel response to a BrowserKit response.

Parameters

object $response The origin response to filter

Return Value

Response An BrowserKit Response instance

in Client at line 530
protected Crawler|null createCrawlerFromContent(string $uri, string $content, string $type)

Creates a crawler.

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

Parameters

string $uri A URI
string $content Content for the crawler to use
string $type Content type

Return Value

Crawler|null

in Client at line 547
Crawler back()

Goes back in the browser history.

Return Value

Crawler

in Client at line 561
Crawler forward()

Goes forward in the browser history.

Return Value

Crawler

in Client at line 575
Crawler reload()

Reloads the current browser.

Return Value

Crawler

in Client at line 587
Crawler followRedirect()

Follow redirects?

Return Value

Crawler

Exceptions

LogicException If request was not a redirect

in Client at line 651
restart()

Restarts the client.

It flushes history and all cookies.

in Client at line 664
protected string getAbsoluteUri(string $uri)

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

Parameters

string $uri A URI

Return Value

string An absolute URI

in Client at line 711
protected Crawler requestFromRequest(Request $request, bool $changeHistory = true)

Makes a request from a Request object directly.

Parameters

Request $request A Request instance
bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())

Return Value

Crawler

at line 56
catchExceptions(bool $catchExceptions)

Sets whether to catch exceptions when the kernel is handling a request.

Parameters

bool $catchExceptions Whether to catch exceptions

at line 118
protected getHandleScript()

at line 160
protected array filterFiles(array $files)

Filters an array of files.

This method created test instances of UploadedFile so that the move() method can be called on those instances.

If the size of a file is greater than the allowed size (from php.ini) then an invalid UploadedFile is returned with an error set to UPLOAD_ERR_INI_SIZE.

Parameters

array $files

Return Value

array An array with all uploaded files marked as already moved

See also

UploadedFile