MakesHttpRequests
trait MakesHttpRequests (View source)
Traits
InteractsWithPages |
Properties
protected Crawler | $crawler | The DomCrawler instance. | from InteractsWithPages |
protected array | $subCrawlers | Nested crawler instances used by the "within" method. | from InteractsWithPages |
protected array | $inputs | All of the stored inputs for the current page. | from InteractsWithPages |
protected array | $uploads | All of the stored uploads for the current page. | from InteractsWithPages |
protected Response | $response | The last response returned by the application. | |
protected string | $currentUri | The current URL being viewed. | |
protected array | $serverVariables | Additional server variables for the request. |
Methods
$this | visit(string $uri) Visit the given URI with a GET request. | from InteractsWithPages |
$this | visitRoute(string $route, array $parameters = []) Visit the given named route with a GET request. | from InteractsWithPages |
$this | makeRequest(string $method, string $uri, array $parameters = [], array $cookies = [], array $files = []) Make a request to the application and create a Crawler instance. | from InteractsWithPages |
$this | resetPageContext() Clean the crawler and the subcrawlers values to reset the page context. | from InteractsWithPages |
$this | makeRequestUsingForm(Form $form, array $uploads = []) Make a request to the application using the given form. | from InteractsWithPages |
array | extractParametersFromForm(Form $form) Extract the parameters from the given form. | from InteractsWithPages |
$this | followRedirects() Follow redirects from the last response. | from InteractsWithPages |
$this | clearInputs() Clear the inputs for the current page. | from InteractsWithPages |
$this | seePageIs(string $uri) Assert that the current page matches a given URI. | from InteractsWithPages |
$this | seeRouteIs(string $route, array $parameters = []) Assert that the current page matches a given named route. | from InteractsWithPages |
$this | assertPageLoaded(string $uri, string|null $message = null) Assert that a given page successfully loaded. | from InteractsWithPages |
$this | within(string $element, Closure $callback) Narrow the test content to a specific area of the page. | from InteractsWithPages |
Crawler | crawler() Get the current crawler according to the test context. | from InteractsWithPages |
$this | assertInPage(PageConstraint $constraint, bool $reverse = false, string $message = '') Assert the given constraint. | from InteractsWithPages |
$this | see(string $text, bool $negate = false) Assert that a given string is seen on the current HTML. | from InteractsWithPages |
$this | dontSee(string $text) Assert that a given string is not seen on the current HTML. | from InteractsWithPages |
$this | seeElement(string $selector, array $attributes = [], bool $negate = false) Assert that an element is present on the page. | from InteractsWithPages |
$this | dontSeeElement(string $selector, array $attributes = []) Assert that an element is not present on the page. | from InteractsWithPages |
$this | seeText(string $text, bool $negate = false) Assert that a given string is seen on the current text. | from InteractsWithPages |
$this | dontSeeText(string $text) Assert that a given string is not seen on the current text. | from InteractsWithPages |
$this | seeInElement(string $element, string $text, bool $negate = false) Assert that a given string is seen inside an element. | from InteractsWithPages |
$this | dontSeeInElement(string $element, string $text) Assert that a given string is not seen inside an element. | from InteractsWithPages |
$this | seeLink(string $text, string|null $url = null, bool $negate = false) Assert that a given link is seen on the page. | from InteractsWithPages |
$this | dontSeeLink(string $text, string|null $url = null) Assert that a given link is not seen on the page. | from InteractsWithPages |
$this | seeInField(string $selector, string $expected, bool $negate = false) Assert that an input field contains the given value. | from InteractsWithPages |
$this | dontSeeInField(string $selector, string $value) Assert that an input field does not contain the given value. | from InteractsWithPages |
$this | seeIsSelected(string $selector, string $value, bool $negate = false) Assert that the expected value is selected. | from InteractsWithPages |
$this | dontSeeIsSelected(string $selector, string $value) Assert that the given value is not selected. | from InteractsWithPages |
$this | seeIsChecked(string $selector, bool $negate = false) Assert that the given checkbox is selected. | from InteractsWithPages |
$this | dontSeeIsChecked(string $selector) Assert that the given checkbox is not selected. | from InteractsWithPages |
$this | click(string $name) Click a link with the given body, name, or ID attribute. | from InteractsWithPages |
$this | type(string $text, string $element) Fill an input field with the given text. | from InteractsWithPages |
$this | check(string $element) Check a checkbox on the page. | from InteractsWithPages |
$this | uncheck(string $element) Uncheck a checkbox on the page. | from InteractsWithPages |
$this | select(string $option, string $element) Select an option from a drop-down. | from InteractsWithPages |
$this | attach(string $absolutePath, string $element) Attach a file to a form field on the page. | from InteractsWithPages |
$this | press(string $buttonText) Submit a form using the button with the given text value. | from InteractsWithPages |
$this | submitForm(string $buttonText, array $inputs = [], array $uploads = []) Submit a form on the page with the given input. | from InteractsWithPages |
Form | fillForm(string $buttonText, array $inputs = []) Fill the form with the given data. | from InteractsWithPages |
Form | getForm(string|null $buttonText = null) Get the form from the page with the given submit button text. | from InteractsWithPages |
$this | storeInput(string $element, string $text) Store a form input in the local array. | from InteractsWithPages |
$this | assertFilterProducesResults(string $filter) Assert that a filtered Crawler returns nodes. | from InteractsWithPages |
Crawler | filterByNameOrId(string $name, array|string $elements = '*') Filter elements according to the given name or ID attribute. | from InteractsWithPages |
array | convertUploadsForTesting(Form $form, array $uploads) Convert the given uploads to UploadedFile instances. | from InteractsWithPages |
prepareArrayBasedFileInput(array $uploads, string $key, mixed $file) Store an array based file upload with the proper nested array structure. | from InteractsWithPages | |
UploadedFile | getUploadedFileForTesting(array $file, array $uploads, string $name) Create an UploadedFile instance for testing. | from InteractsWithPages |
$this | withoutMiddleware() Disable middleware for the test. | |
$this | json(string $method, string $uri, array $data = [], array $headers = []) Visit the given URI with a JSON request. | |
array | extractFilesFromDataArray(array $data) Extract the file uploads from the given data array. | |
$this | get(string $uri, array $headers = []) Visit the given URI with a GET request. | |
$this | getJson(string $uri, array $headers = []) Visit the given URI with a GET request, expecting a JSON response. | |
$this | post(string $uri, array $data = [], array $headers = []) Visit the given URI with a POST request. | |
$this | postJson(string $uri, array $data = [], array $headers = []) Visit the given URI with a POST request, expecting a JSON response. | |
$this | put(string $uri, array $data = [], array $headers = []) Visit the given URI with a PUT request. | |
$this | putJson(string $uri, array $data = [], array $headers = []) Visit the given URI with a PUT request, expecting a JSON response. | |
$this | patch(string $uri, array $data = [], array $headers = []) Visit the given URI with a PATCH request. | |
$this | patchJson(string $uri, array $data = [], array $headers = []) Visit the given URI with a PATCH request, expecting a JSON response. | |
$this | delete(string $uri, array $data = [], array $headers = []) Visit the given URI with a DELETE request. | |
$this | deleteJson(string $uri, array $data = [], array $headers = []) Visit the given URI with a DELETE request, expecting a JSON response. | |
$this | handle(Request $request) Send the given request through the application. | |
$this | shouldReturnJson(array $data = null) Assert that the response contains JSON. | |
$this|null | receiveJson(array $data = null) Assert that the response contains JSON. | |
$this | seeJsonEquals(array $data) Assert that the response contains an exact JSON array. | |
$this | seeJson(array $data = null, bool $negate = false) Assert that the response contains JSON. | |
$this | dontSeeJson(array $data = null) Assert that the response doesn't contain JSON. | |
$this | seeJsonStructure(array $structure = null, array|null $responseData = null) Assert that the JSON response has a given structure. | |
$this | seeJsonContains(array $data, bool $negate = false) Assert that the response contains the given JSON. | |
$this | seeJsonSubset(array $data) Assert that the response is a superset of the given JSON. | |
array | decodeResponseJson() Validate and return the decoded response JSON. | |
string | formatToExpectedJson(string $key, mixed $value) Format the given key and value into a JSON string for expectation checks. | |
$this | seeStatusCode(int $status) Asserts that the status code of the response matches the given code. | |
$this | seeHeader(string $headerName, mixed $value = null) Asserts that the response contains the given header and equals the optional value. | |
$this | seePlainCookie(string $cookieName, mixed $value = null) Asserts that the response contains the given cookie and equals the optional value. | |
$this | seeCookie(string $cookieName, mixed $value = null, bool $encrypted = true) Asserts that the response contains the given cookie and equals the optional value. | |
$this | withServerVariables(array $server) Define a set of server variables to be sent with the requests. | |
Response | call(string $method, string $uri, array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null) Call the given URI and return the Response. | |
Response | callSecure(string $method, string $uri, array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null) Call the given HTTPS URI and return the Response. | |
Response | action(string $method, string $action, array $wildcards = [], array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null) Call a controller action and return the Response. | |
Response | route(string $method, string $name, array $routeParameters = [], array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null) Call a named route and return the Response. | |
string | prepareUrlForRequest(string $uri) Turn the given URI into a fully qualified URL. | |
array | transformHeadersToServerVars(array $headers) Transform headers array to array of $SERVER vars with HTTP* format. | |
mixed | filterFiles(array $files) Filter the given array of files, removing any empty values. | |
$this | assertResponseOk() Assert that the client response has an OK status code. | |
$this | assertResponseStatus(int $code) Assert that the client response has a given code. | |
$this | assertViewHas(string|array $key, mixed $value = null) Assert that the response view has a given piece of bound data. | |
$this | assertViewHasAll(array $bindings) Assert that the view has a given list of bound data. | |
$this | assertViewMissing(string $key) Assert that the response view is missing a piece of bound data. | |
$this | assertRedirectedTo(string $uri, array $with = []) Assert whether the client was redirected to a given URI. | |
$this | assertRedirectedToRoute(string $name, array $parameters = [], array $with = []) Assert whether the client was redirected to a given route. | |
$this | assertRedirectedToAction(string $name, array $parameters = [], array $with = []) Assert whether the client was redirected to a given action. | |
void | dump() Dump the content from the last response. |
Details
$this visit(string $uri)
Visit the given URI with a GET request.
$this visitRoute(string $route, array $parameters = [])
Visit the given named route with a GET request.
protected $this makeRequest(string $method, string $uri, array $parameters = [], array $cookies = [], array $files = [])
Make a request to the application and create a Crawler instance.
protected $this resetPageContext()
Clean the crawler and the subcrawlers values to reset the page context.
protected $this makeRequestUsingForm(Form $form, array $uploads = [])
Make a request to the application using the given form.
protected array extractParametersFromForm(Form $form)
Extract the parameters from the given form.
protected $this followRedirects()
Follow redirects from the last response.
protected $this clearInputs()
Clear the inputs for the current page.
protected $this seePageIs(string $uri)
Assert that the current page matches a given URI.
protected $this seeRouteIs(string $route, array $parameters = [])
Assert that the current page matches a given named route.
protected $this assertPageLoaded(string $uri, string|null $message = null)
Assert that a given page successfully loaded.
$this within(string $element, Closure $callback)
Narrow the test content to a specific area of the page.
protected Crawler crawler()
Get the current crawler according to the test context.
protected $this assertInPage(PageConstraint $constraint, bool $reverse = false, string $message = '')
Assert the given constraint.
$this see(string $text, bool $negate = false)
Assert that a given string is seen on the current HTML.
$this dontSee(string $text)
Assert that a given string is not seen on the current HTML.
$this seeElement(string $selector, array $attributes = [], bool $negate = false)
Assert that an element is present on the page.
$this dontSeeElement(string $selector, array $attributes = [])
Assert that an element is not present on the page.
$this seeText(string $text, bool $negate = false)
Assert that a given string is seen on the current text.
$this dontSeeText(string $text)
Assert that a given string is not seen on the current text.
$this seeInElement(string $element, string $text, bool $negate = false)
Assert that a given string is seen inside an element.
$this dontSeeInElement(string $element, string $text)
Assert that a given string is not seen inside an element.
$this seeLink(string $text, string|null $url = null, bool $negate = false)
Assert that a given link is seen on the page.
$this dontSeeLink(string $text, string|null $url = null)
Assert that a given link is not seen on the page.
$this seeInField(string $selector, string $expected, bool $negate = false)
Assert that an input field contains the given value.
$this dontSeeInField(string $selector, string $value)
Assert that an input field does not contain the given value.
$this seeIsSelected(string $selector, string $value, bool $negate = false)
Assert that the expected value is selected.
$this dontSeeIsSelected(string $selector, string $value)
Assert that the given value is not selected.
$this seeIsChecked(string $selector, bool $negate = false)
Assert that the given checkbox is selected.
$this dontSeeIsChecked(string $selector)
Assert that the given checkbox is not selected.
protected $this click(string $name)
Click a link with the given body, name, or ID attribute.
protected $this type(string $text, string $element)
Fill an input field with the given text.
protected $this check(string $element)
Check a checkbox on the page.
protected $this uncheck(string $element)
Uncheck a checkbox on the page.
protected $this select(string $option, string $element)
Select an option from a drop-down.
protected $this attach(string $absolutePath, string $element)
Attach a file to a form field on the page.
protected $this press(string $buttonText)
Submit a form using the button with the given text value.
protected $this submitForm(string $buttonText, array $inputs = [], array $uploads = [])
Submit a form on the page with the given input.
protected Form fillForm(string $buttonText, array $inputs = [])
Fill the form with the given data.
protected Form getForm(string|null $buttonText = null)
Get the form from the page with the given submit button text.
protected $this storeInput(string $element, string $text)
Store a form input in the local array.
protected $this assertFilterProducesResults(string $filter)
Assert that a filtered Crawler returns nodes.
protected Crawler filterByNameOrId(string $name, array|string $elements = '*')
Filter elements according to the given name or ID attribute.
protected array convertUploadsForTesting(Form $form, array $uploads)
Convert the given uploads to UploadedFile instances.
protected prepareArrayBasedFileInput(array $uploads, string $key, mixed $file)
Store an array based file upload with the proper nested array structure.
protected UploadedFile getUploadedFileForTesting(array $file, array $uploads, string $name)
Create an UploadedFile instance for testing.
$this withoutMiddleware()
Disable middleware for the test.
$this json(string $method, string $uri, array $data = [], array $headers = [])
Visit the given URI with a JSON request.
protected array extractFilesFromDataArray(array $data)
Extract the file uploads from the given data array.
$this get(string $uri, array $headers = [])
Visit the given URI with a GET request.
$this getJson(string $uri, array $headers = [])
Visit the given URI with a GET request, expecting a JSON response.
$this post(string $uri, array $data = [], array $headers = [])
Visit the given URI with a POST request.
$this postJson(string $uri, array $data = [], array $headers = [])
Visit the given URI with a POST request, expecting a JSON response.
$this put(string $uri, array $data = [], array $headers = [])
Visit the given URI with a PUT request.
$this putJson(string $uri, array $data = [], array $headers = [])
Visit the given URI with a PUT request, expecting a JSON response.
$this patch(string $uri, array $data = [], array $headers = [])
Visit the given URI with a PATCH request.
$this patchJson(string $uri, array $data = [], array $headers = [])
Visit the given URI with a PATCH request, expecting a JSON response.
$this delete(string $uri, array $data = [], array $headers = [])
Visit the given URI with a DELETE request.
$this deleteJson(string $uri, array $data = [], array $headers = [])
Visit the given URI with a DELETE request, expecting a JSON response.
$this handle(Request $request)
Send the given request through the application.
This method allows you to fully customize the entire Request object.
protected $this shouldReturnJson(array $data = null)
Assert that the response contains JSON.
protected $this|null receiveJson(array $data = null)
Assert that the response contains JSON.
$this seeJsonEquals(array $data)
Assert that the response contains an exact JSON array.
$this seeJson(array $data = null, bool $negate = false)
Assert that the response contains JSON.
$this dontSeeJson(array $data = null)
Assert that the response doesn't contain JSON.
$this seeJsonStructure(array $structure = null, array|null $responseData = null)
Assert that the JSON response has a given structure.
protected $this seeJsonContains(array $data, bool $negate = false)
Assert that the response contains the given JSON.
protected $this seeJsonSubset(array $data)
Assert that the response is a superset of the given JSON.
protected array decodeResponseJson()
Validate and return the decoded response JSON.
protected string formatToExpectedJson(string $key, mixed $value)
Format the given key and value into a JSON string for expectation checks.
protected $this seeStatusCode(int $status)
Asserts that the status code of the response matches the given code.
protected $this seeHeader(string $headerName, mixed $value = null)
Asserts that the response contains the given header and equals the optional value.
protected $this seePlainCookie(string $cookieName, mixed $value = null)
Asserts that the response contains the given cookie and equals the optional value.
protected $this seeCookie(string $cookieName, mixed $value = null, bool $encrypted = true)
Asserts that the response contains the given cookie and equals the optional value.
protected $this withServerVariables(array $server)
Define a set of server variables to be sent with the requests.
Response call(string $method, string $uri, array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null)
Call the given URI and return the Response.
Response callSecure(string $method, string $uri, array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null)
Call the given HTTPS URI and return the Response.
Response action(string $method, string $action, array $wildcards = [], array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null)
Call a controller action and return the Response.
Response route(string $method, string $name, array $routeParameters = [], array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null)
Call a named route and return the Response.
protected string prepareUrlForRequest(string $uri)
Turn the given URI into a fully qualified URL.
protected array transformHeadersToServerVars(array $headers)
Transform headers array to array of $SERVER vars with HTTP* format.
protected mixed filterFiles(array $files)
Filter the given array of files, removing any empty values.
$this assertResponseOk()
Assert that the client response has an OK status code.
$this assertResponseStatus(int $code)
Assert that the client response has a given code.
$this assertViewHas(string|array $key, mixed $value = null)
Assert that the response view has a given piece of bound data.
$this assertViewHasAll(array $bindings)
Assert that the view has a given list of bound data.
$this assertViewMissing(string $key)
Assert that the response view is missing a piece of bound data.
$this assertRedirectedTo(string $uri, array $with = [])
Assert whether the client was redirected to a given URI.
$this assertRedirectedToRoute(string $name, array $parameters = [], array $with = [])
Assert whether the client was redirected to a given route.
$this assertRedirectedToAction(string $name, array $parameters = [], array $with = [])
Assert whether the client was redirected to a given action.
void dump()
Dump the content from the last response.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.3/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.html