PHP Trait Laravel\Lumen\Testing\CrawlerTrait

Show file Open project: ctrlaltdylan/MirrorMirror

Protected Properties

Property Type Description
$crawler Symfony\Component\DomCrawler\Crawler The DomCrawler instance.
$currentUri string The current URL being viewed.
$inputs array All of the stored inputs for the current page.
$response Illuminate\Http\Response The last response returned by the application.

Public Methods

Method Description
action ( string $method, string $action, array $wildcards = [], array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null ) : Illuminate\Http\Response Call a controller action and return the Response.
call ( string $method, string $uri, array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null ) : Illuminate\Http\Response Call the given URI and return the Response.
callSecure ( string $method, string $uri, array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null ) : Illuminate\Http\Response Call the given HTTPS URI and return the Response.
delete ( string $uri, array $data = [], array $headers = [] ) Visit the given URI with a DELETE request.
dump ( ) : void Dump the content from the last response.
get ( string $uri, array $headers = [] ) Visit the given URI with a GET request.
handle ( Illuminate\Http\Request $request ) Send the given request through the application.
patch ( string $uri, array $data = [], array $headers = [] ) Visit the given URI with a PATCH request.
post ( string $uri, array $data = [], array $headers = [] ) Visit the given URI with a POST request.
put ( string $uri, array $data = [], array $headers = [] ) Visit the given URI with a PUT request.
route ( string $method, string $name, array $routeParameters = [], array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null ) : Illuminate\Http\Response Call a named route and return the Response.
seeJson ( array $data = null ) Assert that the response contains JSON.
seeJsonEquals ( array $data ) Assert that the response contains an exact JSON array.
visit ( string $uri ) Visit the given URI with a GET request.
withoutMiddleware ( ) Disable middleware for the test.

Protected Methods

Method Description
assertFilterProducesResults ( string $filter ) : void Assert that a filtered Crawler returns nodes.
assertPageLoaded ( string $uri, string | null $message = null ) : void Assert that a given page successfully loaded.
attach ( string $absolutePath, string $element ) Attach a file to a form field on the page.
check ( string $element ) Check a checkbox on the page.
clearInputs ( ) Clear the inputs for the current page.
click ( string $name ) Click a link with the given body, name, or ID attribute.
dontSee ( string $text ) Assert that a given string is not seen on the page.
extractParametersFromForm ( Form $form ) : array Extract the parameters from the given form.
fillForm ( string $buttonText, array $inputs = [] ) : Form Fill the form with the given data.
filterByNameOrId ( string $name, string $element = '*' ) : Crawler Filter elements according to the given name or ID attribute.
followRedirects ( ) Follow redirects from the last response.
formatToExpectedJson ( string $key, mixed $value ) : string Format the given key and value into a JSON string for expectation checks.
getForm ( string | null $buttonText = null ) : Form Get the form from the page with the given submit button text.
landOn ( string $uri ) Assert that the current page matches a given URI.
makeRequest ( string $method, string $uri, array $parameters = [], array $cookies = [], array $files = [] ) Make a request to the application and create a Crawler instance.
makeRequestUsingForm ( Form $form ) Make a request to the application using the given form.
onPage ( string $uri ) Assert that the current page matches a given URI.
prepareUrlForRequest ( string $uri ) : string Turn the given URI into a fully qualified URL.
press ( string $buttonText ) Submit a form using the button with the given text value.
receiveJson ( array | null $data = null ) Assert that the response contains JSON.
see ( string $text, boolean $negate = false ) Assert that a given string is seen on the page.
seeJsonContains ( array $data ) Assert that the response contains the given JSON.
seePageIs ( string $uri ) Assert that the current page matches a given URI.
seeStatusCode ( integer $status ) Asserts that the status code of the response matches the given code.
select ( string $option, string $element ) Select an option from a drop-down.
shouldReturnJson ( array $data = null ) Assert that the response contains JSON.
storeInput ( string $element, string $text ) Store a form input in the local array.
submitForm ( string $buttonText, array $inputs = [] ) Submit a form on the page with the given input.
transformHeadersToServerVars ( array $headers ) : array Transform headers array to array of $_SERVER vars with HTTP_* format.
type ( string $text, string $element ) Fill an input field with the given text.

Method Details

action() public method

Call a controller action and return the Response.
public action ( string $method, string $action, array $wildcards = [], array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null ) : Illuminate\Http\Response
$method string
$action string
$wildcards array
$parameters array
$cookies array
$files array
$server array
$content string
return Illuminate\Http\Response

assertFilterProducesResults() protected method

Assert that a filtered Crawler returns nodes.
protected assertFilterProducesResults ( string $filter ) : void
$filter string
return void

assertPageLoaded() protected method

Assert that a given page successfully loaded.
protected assertPageLoaded ( string $uri, string | null $message = null ) : void
$uri string
$message string | null
return void

attach() protected method

Attach a file to a form field on the page.
protected attach ( string $absolutePath, string $element )
$absolutePath string
$element string

call() public method

Call the given URI and return the Response.
public call ( string $method, string $uri, array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null ) : Illuminate\Http\Response
$method string
$uri string
$parameters array
$cookies array
$files array
$server array
$content string
return Illuminate\Http\Response

callSecure() public method

Call the given HTTPS URI and return the Response.
public callSecure ( string $method, string $uri, array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null ) : Illuminate\Http\Response
$method string
$uri string
$parameters array
$cookies array
$files array
$server array
$content string
return Illuminate\Http\Response

check() protected method

Check a checkbox on the page.
protected check ( string $element )
$element string

clearInputs() protected method

Clear the inputs for the current page.
protected clearInputs ( )

click() protected method

Click a link with the given body, name, or ID attribute.
protected click ( string $name )
$name string

delete() public method

Visit the given URI with a DELETE request.
public delete ( string $uri, array $data = [], array $headers = [] )
$uri string
$data array
$headers array

dontSee() protected method

Assert that a given string is not seen on the page.
protected dontSee ( string $text )
$text string

dump() public method

Dump the content from the last response.
public dump ( ) : void
return void

extractParametersFromForm() protected method

Extract the parameters from the given form.
protected extractParametersFromForm ( Form $form ) : array
$form Symfony\Component\DomCrawler\Form
return array

fillForm() protected method

Fill the form with the given data.
protected fillForm ( string $buttonText, array $inputs = [] ) : Form
$buttonText string
$inputs array
return Symfony\Component\DomCrawler\Form

filterByNameOrId() protected method

Filter elements according to the given name or ID attribute.
protected filterByNameOrId ( string $name, string $element = '*' ) : Crawler
$name string
$element string
return Symfony\Component\DomCrawler\Crawler

followRedirects() protected method

Follow redirects from the last response.
protected followRedirects ( )

formatToExpectedJson() protected method

Format the given key and value into a JSON string for expectation checks.
protected formatToExpectedJson ( string $key, mixed $value ) : string
$key string
$value mixed
return string

get() public method

Visit the given URI with a GET request.
public get ( string $uri, array $headers = [] )
$uri string
$headers array

getForm() protected method

Get the form from the page with the given submit button text.
protected getForm ( string | null $buttonText = null ) : Form
$buttonText string | null
return Symfony\Component\DomCrawler\Form

handle() public method

Send the given request through the application.
public handle ( Illuminate\Http\Request $request )
$request Illuminate\Http\Request

landOn() protected method

Assert that the current page matches a given URI.
protected landOn ( string $uri )
$uri string

makeRequest() protected method

Make a request to the application and create a Crawler instance.
protected makeRequest ( string $method, string $uri, array $parameters = [], array $cookies = [], array $files = [] )
$method string
$uri string
$parameters array
$cookies array
$files array

makeRequestUsingForm() protected method

Make a request to the application using the given form.
protected makeRequestUsingForm ( Form $form )
$form Symfony\Component\DomCrawler\Form

onPage() protected method

Assert that the current page matches a given URI.
protected onPage ( string $uri )
$uri string

patch() public method

Visit the given URI with a PATCH request.
public patch ( string $uri, array $data = [], array $headers = [] )
$uri string
$data array
$headers array

post() public method

Visit the given URI with a POST request.
public post ( string $uri, array $data = [], array $headers = [] )
$uri string
$data array
$headers array

prepareUrlForRequest() protected method

Turn the given URI into a fully qualified URL.
protected prepareUrlForRequest ( string $uri ) : string
$uri string
return string

press() protected method

Submit a form using the button with the given text value.
protected press ( string $buttonText )
$buttonText string

put() public method

Visit the given URI with a PUT request.
public put ( string $uri, array $data = [], array $headers = [] )
$uri string
$data array
$headers array

receiveJson() protected method

Assert that the response contains JSON.
protected receiveJson ( array | null $data = null )
$data array | null

route() public method

Call a named route and return the Response.
public route ( string $method, string $name, array $routeParameters = [], array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null ) : Illuminate\Http\Response
$method string
$name string
$routeParameters array
$parameters array
$cookies array
$files array
$server array
$content string
return Illuminate\Http\Response

see() protected method

Assert that a given string is seen on the page.
protected see ( string $text, boolean $negate = false )
$text string
$negate boolean

seeJson() public method

Assert that the response contains JSON.
public seeJson ( array $data = null )
$data array

seeJsonContains() protected method

Assert that the response contains the given JSON.
protected seeJsonContains ( array $data )
$data array

seeJsonEquals() public method

Assert that the response contains an exact JSON array.
public seeJsonEquals ( array $data )
$data array

seePageIs() protected method

Assert that the current page matches a given URI.
protected seePageIs ( string $uri )
$uri string

seeStatusCode() protected method

Asserts that the status code of the response matches the given code.
protected seeStatusCode ( integer $status )
$status integer

select() protected method

Select an option from a drop-down.
protected select ( string $option, string $element )
$option string
$element string

shouldReturnJson() protected method

Assert that the response contains JSON.
protected shouldReturnJson ( array $data = null )
$data array

storeInput() protected method

Store a form input in the local array.
protected storeInput ( string $element, string $text )
$element string
$text string

submitForm() protected method

Submit a form on the page with the given input.
protected submitForm ( string $buttonText, array $inputs = [] )
$buttonText string
$inputs array

transformHeadersToServerVars() protected method

Transform headers array to array of $_SERVER vars with HTTP_* format.
protected transformHeadersToServerVars ( array $headers ) : array
$headers array
return array

type() protected method

Fill an input field with the given text.
protected type ( string $text, string $element )
$text string
$element string

visit() public method

Visit the given URI with a GET request.
public visit ( string $uri )
$uri string

withoutMiddleware() public method

Disable middleware for the test.
public withoutMiddleware ( )

Property Details

$crawler protected property

The DomCrawler instance.
protected Crawler,Symfony\Component\DomCrawler $crawler
return Symfony\Component\DomCrawler\Crawler

$currentUri protected property

The current URL being viewed.
protected string $currentUri
return string

$inputs protected property

All of the stored inputs for the current page.
protected array $inputs
return array

$response protected property

The last response returned by the application.
protected Response,Illuminate\Http $response
return Illuminate\Http\Response