TestCase

class TestCase extends PHPUnit_Framework_TestCase (View source)

Traits

InteractsWithContainer
MakesHttpRequests
ImpersonatesUsers
InteractsWithAuthentication
InteractsWithConsole
InteractsWithDatabase
InteractsWithSession
MocksApplicationServices
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. from MakesHttpRequests
protected string $currentUri The current URL being viewed. from MakesHttpRequests
protected array $serverVariables Additional server variables for the request. from MakesHttpRequests
protected int $code The last code returned by Artisan CLI. from InteractsWithConsole
protected array $firedEvents All of the fired events. from MocksApplicationServices
protected array $firedModelEvents All of the fired model events. from MocksApplicationServices
protected array $dispatchedJobs All of the dispatched jobs. from MocksApplicationServices
protected array $dispatchedNotifications All of the dispatched notifications. from MocksApplicationServices
protected Application $app The Illuminate application instance.
protected array $afterApplicationCreatedCallbacks The callbacks that should be run after the application is created.
protected array $beforeApplicationDestroyedCallbacks The callbacks that should be run before the application is destroyed.
protected bool $setUpHasRun Indicates if we have made it through the base setUp function.

Methods

object instance(string $abstract, object $instance)

Register an instance of an object in the container.

from InteractsWithContainer
$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.

from MakesHttpRequests
$this json(string $method, string $uri, array $data = [], array $headers = [])

Visit the given URI with a JSON request.

from MakesHttpRequests
array extractFilesFromDataArray(array $data)

Extract the file uploads from the given data array.

from MakesHttpRequests
$this get(string $uri, array $headers = [])

Visit the given URI with a GET request.

from MakesHttpRequests
$this getJson(string $uri, array $headers = [])

Visit the given URI with a GET request, expecting a JSON response.

from MakesHttpRequests
$this post(string $uri, array $data = [], array $headers = [])

Visit the given URI with a POST request.

from MakesHttpRequests
$this postJson(string $uri, array $data = [], array $headers = [])

Visit the given URI with a POST request, expecting a JSON response.

from MakesHttpRequests
$this put(string $uri, array $data = [], array $headers = [])

Visit the given URI with a PUT request.

from MakesHttpRequests
$this putJson(string $uri, array $data = [], array $headers = [])

Visit the given URI with a PUT request, expecting a JSON response.

from MakesHttpRequests
$this patch(string $uri, array $data = [], array $headers = [])

Visit the given URI with a PATCH request.

from MakesHttpRequests
$this patchJson(string $uri, array $data = [], array $headers = [])

Visit the given URI with a PATCH request, expecting a JSON response.

from MakesHttpRequests
$this delete(string $uri, array $data = [], array $headers = [])

Visit the given URI with a DELETE request.

from MakesHttpRequests
$this deleteJson(string $uri, array $data = [], array $headers = [])

Visit the given URI with a DELETE request, expecting a JSON response.

from MakesHttpRequests
$this handle(Request $request)

Send the given request through the application.

from MakesHttpRequests
$this shouldReturnJson(array $data = null)

Assert that the response contains JSON.

from MakesHttpRequests
$this|null receiveJson(array $data = null)

Assert that the response contains JSON.

from MakesHttpRequests
$this seeJsonEquals(array $data)

Assert that the response contains an exact JSON array.

from MakesHttpRequests
$this seeJson(array $data = null, bool $negate = false)

Assert that the response contains JSON.

from MakesHttpRequests
$this dontSeeJson(array $data = null)

Assert that the response doesn't contain JSON.

from MakesHttpRequests
$this seeJsonStructure(array $structure = null, array|null $responseData = null)

Assert that the JSON response has a given structure.

from MakesHttpRequests
$this seeJsonContains(array $data, bool $negate = false)

Assert that the response contains the given JSON.

from MakesHttpRequests
$this seeJsonSubset(array $data)

Assert that the response is a superset of the given JSON.

from MakesHttpRequests
array decodeResponseJson()

Validate and return the decoded response JSON.

from MakesHttpRequests
string formatToExpectedJson(string $key, mixed $value)

Format the given key and value into a JSON string for expectation checks.

from MakesHttpRequests
$this seeStatusCode(int $status)

Asserts that the status code of the response matches the given code.

from MakesHttpRequests
$this seeHeader(string $headerName, mixed $value = null)

Asserts that the response contains the given header and equals the optional value.

from MakesHttpRequests
$this seePlainCookie(string $cookieName, mixed $value = null)

Asserts that the response contains the given cookie and equals the optional value.

from MakesHttpRequests
$this seeCookie(string $cookieName, mixed $value = null, bool $encrypted = true)

Asserts that the response contains the given cookie and equals the optional value.

from MakesHttpRequests
$this withServerVariables(array $server)

Define a set of server variables to be sent with the requests.

from MakesHttpRequests
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.

from MakesHttpRequests
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.

from MakesHttpRequests
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.

from MakesHttpRequests
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.

from MakesHttpRequests
string prepareUrlForRequest(string $uri)

Turn the given URI into a fully qualified URL.

from MakesHttpRequests
array transformHeadersToServerVars(array $headers)

Transform headers array to array of $SERVER vars with HTTP* format.

from MakesHttpRequests
mixed filterFiles(array $files)

Filter the given array of files, removing any empty values.

from MakesHttpRequests
$this assertResponseOk()

Assert that the client response has an OK status code.

from MakesHttpRequests
$this assertResponseStatus(int $code)

Assert that the client response has a given code.

from MakesHttpRequests
$this assertViewHas(string|array $key, mixed $value = null)

Assert that the response view has a given piece of bound data.

from MakesHttpRequests
$this assertViewHasAll(array $bindings)

Assert that the view has a given list of bound data.

from MakesHttpRequests
$this assertViewMissing(string $key)

Assert that the response view is missing a piece of bound data.

from MakesHttpRequests
$this assertRedirectedTo(string $uri, array $with = [])

Assert whether the client was redirected to a given URI.

from MakesHttpRequests
$this assertRedirectedToRoute(string $name, array $parameters = [], array $with = [])

Assert whether the client was redirected to a given route.

from MakesHttpRequests
$this assertRedirectedToAction(string $name, array $parameters = [], array $with = [])

Assert whether the client was redirected to a given action.

from MakesHttpRequests
void dump()

Dump the content from the last response.

from MakesHttpRequests
$this actingAs(Authenticatable $user, string|null $driver = null)

Set the currently logged in user for the application.

from ImpersonatesUsers
$this be(Authenticatable $user, string|null $driver = null)

Set the currently logged in user for the application.

from ImpersonatesUsers
$this seeIsAuthenticated(string|null $guard = null)

Assert that the user is authenticated.

from InteractsWithAuthentication
$this dontSeeIsAuthenticated(string|null $guard = null)

Assert that the user is not authenticated.

from InteractsWithAuthentication
bool isAuthenticated(string|null $guard = null)

Return true if the user is authenticated, false otherwise.

from InteractsWithAuthentication
$this seeIsAuthenticatedAs($user, string|null $guard = null)

Assert that the user is authenticated as the given user.

from InteractsWithAuthentication
$this seeCredentials(array $credentials, string|null $guard = null)

Assert that the given credentials are valid.

from InteractsWithAuthentication
$this dontSeeCredentials(array $credentials, string|null $guard = null)

Assert that the given credentials are invalid.

from InteractsWithAuthentication
bool hasCredentials(array $credentials, string|null $guard = null)

Return true is the credentials are valid, false otherwise.

from InteractsWithAuthentication
int artisan(string $command, array $parameters = [])

Call artisan command and return code.

from InteractsWithConsole
$this seeInDatabase(string $table, array $data, string $connection = null)

Assert that a given where condition exists in the database.

from InteractsWithDatabase
$this missingFromDatabase(string $table, array $data, string $connection = null)

Assert that a given where condition does not exist in the database.

from InteractsWithDatabase
$this dontSeeInDatabase(string $table, array $data, string $connection = null)

Assert that a given where condition does not exist in the database.

from InteractsWithDatabase
$this notSeeInDatabase(string $table, array $data, string $connection = null)

Assert that a given where condition does not exist in the database.

from InteractsWithDatabase
$this seed(string $class = 'DatabaseSeeder')

Seed a given database connection.

from InteractsWithDatabase
$this withSession(array $data)

Set the session to the given array.

from InteractsWithSession
$this session(array $data)

Set the session to the given array.

from InteractsWithSession
$this startSession()

Start the session for the application.

from InteractsWithSession
$this flushSession()

Flush all of the current session data.

from InteractsWithSession
$this seeInSession(string|array $key, mixed $value = null)

Assert that the session has a given value.

from InteractsWithSession
$this assertSessionHas(string|array $key, mixed $value = null)

Assert that the session has a given value.

from InteractsWithSession
$this assertSessionHasAll(array $bindings)

Assert that the session has a given list of values.

from InteractsWithSession
$this assertSessionMissing(string|array $key)

Assert that the session does not have a given key.

from InteractsWithSession
$this assertSessionHasErrors(string|array $bindings = [], mixed $format = null)

Assert that the session has errors bound.

from InteractsWithSession
$this assertHasOldInput()

Assert that the session has old input.

from InteractsWithSession
$this expectsEvents(array|string $events)

Specify a list of events that should be fired for the given operation.

from MocksApplicationServices
$this doesntExpectEvents(array|string $events)

Specify a list of events that should not be fired for the given operation.

from MocksApplicationServices
$this withoutEvents()

Mock the event dispatcher so all events are silenced and collected.

from MocksApplicationServices
$this expectsModelEvents(string $model, array|string $events)

Specify a list of events that should be fired for the given operation.

from MocksApplicationServices
$this doesntExpectModelEvents(string $model, array|string $events)

Specify a list of events that should not be fired for the given operation.

from MocksApplicationServices
$this withoutModelEvents()

Mock the model event dispatcher so all Eloquent events are silenced.

from MocksApplicationServices
$this withoutObservers(array|string $observers)

Specify a list of observers that will not run for the given operation.

from MocksApplicationServices
array getFiredEvents(array $events)

Filter the given events against the fired events.

from MocksApplicationServices
array getFiredModelEvents(array $events)

Filter the given events against the fired events.

from MocksApplicationServices
$this expectsJobs(array|string $jobs)

Specify a list of jobs that should be dispatched for the given operation.

from MocksApplicationServices
$this doesntExpectJobs(array|string $jobs)

Specify a list of jobs that should not be dispatched for the given operation.

from MocksApplicationServices
$this withoutJobs()

Mock the job dispatcher so all jobs are silenced and collected.

from MocksApplicationServices
array getDispatchedJobs(array $jobs)

Filter the given jobs against the dispatched jobs.

from MocksApplicationServices
array getDispatched(array $classes, array $dispatched)

Filter the given classes against an array of dispatched classes.

from MocksApplicationServices
bool wasDispatched(string $needle, array $haystack)

Check if the given class exists in an array of dispatched classes.

from MocksApplicationServices
$this withoutNotifications()

Mock the notification dispatcher so all notifications are silenced.

from MocksApplicationServices
$this expectsNotification(mixed $notifiable, string $notification)

Specify a notification that is expected to be dispatched.

from MocksApplicationServices
HttpKernelInterface createApplication()

Creates the application.

void setUp()

Setup the test environment.

void refreshApplication()

Refresh the application instance.

void setUpTraits()

Boot the testing helper traits.

void tearDown()

Clean up the testing environment before the next test.

void afterApplicationCreated(callable $callback)

Register a callback to be run after the application is created.

void beforeApplicationDestroyed(callable $callback)

Register a callback to be run before the application is destroyed.

Details

protected object instance(string $abstract, object $instance)

Register an instance of an object in the container.

Parameters

string $abstract
object $instance

Return Value

object

$this visit(string $uri)

Visit the given URI with a GET request.

Parameters

string $uri

Return Value

$this

$this visitRoute(string $route, array $parameters = [])

Visit the given named route with a GET request.

Parameters

string $route
array $parameters

Return Value

$this

protected $this makeRequest(string $method, string $uri, array $parameters = [], array $cookies = [], array $files = [])

Make a request to the application and create a Crawler instance.

Parameters

string $method
string $uri
array $parameters
array $cookies
array $files

Return Value

$this

protected $this resetPageContext()

Clean the crawler and the subcrawlers values to reset the page context.

Return Value

$this

protected $this makeRequestUsingForm(Form $form, array $uploads = [])

Make a request to the application using the given form.

Parameters

Form $form
array $uploads

Return Value

$this

protected array extractParametersFromForm(Form $form)

Extract the parameters from the given form.

Parameters

Form $form

Return Value

array

protected $this followRedirects()

Follow redirects from the last response.

Return Value

$this

protected $this clearInputs()

Clear the inputs for the current page.

Return Value

$this

protected $this seePageIs(string $uri)

Assert that the current page matches a given URI.

Parameters

string $uri

Return Value

$this

protected $this seeRouteIs(string $route, array $parameters = [])

Assert that the current page matches a given named route.

Parameters

string $route
array $parameters

Return Value

$this

protected $this assertPageLoaded(string $uri, string|null $message = null)

Assert that a given page successfully loaded.

Parameters

string $uri
string|null $message

Return Value

$this

Exceptions

HttpException

$this within(string $element, Closure $callback)

Narrow the test content to a specific area of the page.

Parameters

string $element
Closure $callback

Return Value

$this

protected Crawler crawler()

Get the current crawler according to the test context.

Return Value

Crawler

protected $this assertInPage(PageConstraint $constraint, bool $reverse = false, string $message = '')

Assert the given constraint.

Parameters

PageConstraint $constraint
bool $reverse
string $message

Return Value

$this

$this see(string $text, bool $negate = false)

Assert that a given string is seen on the current HTML.

Parameters

string $text
bool $negate

Return Value

$this

$this dontSee(string $text)

Assert that a given string is not seen on the current HTML.

Parameters

string $text

Return Value

$this

$this seeElement(string $selector, array $attributes = [], bool $negate = false)

Assert that an element is present on the page.

Parameters

string $selector
array $attributes
bool $negate

Return Value

$this

$this dontSeeElement(string $selector, array $attributes = [])

Assert that an element is not present on the page.

Parameters

string $selector
array $attributes

Return Value

$this

$this seeText(string $text, bool $negate = false)

Assert that a given string is seen on the current text.

Parameters

string $text
bool $negate

Return Value

$this

$this dontSeeText(string $text)

Assert that a given string is not seen on the current text.

Parameters

string $text

Return Value

$this

$this seeInElement(string $element, string $text, bool $negate = false)

Assert that a given string is seen inside an element.

Parameters

string $element
string $text
bool $negate

Return Value

$this

$this dontSeeInElement(string $element, string $text)

Assert that a given string is not seen inside an element.

Parameters

string $element
string $text

Return Value

$this

Assert that a given link is seen on the page.

Parameters

string $text
string|null $url
bool $negate

Return Value

$this

Assert that a given link is not seen on the page.

Parameters

string $text
string|null $url

Return Value

$this

$this seeInField(string $selector, string $expected, bool $negate = false)

Assert that an input field contains the given value.

Parameters

string $selector
string $expected
bool $negate

Return Value

$this

$this dontSeeInField(string $selector, string $value)

Assert that an input field does not contain the given value.

Parameters

string $selector
string $value

Return Value

$this

$this seeIsSelected(string $selector, string $value, bool $negate = false)

Assert that the expected value is selected.

Parameters

string $selector
string $value
bool $negate

Return Value

$this

$this dontSeeIsSelected(string $selector, string $value)

Assert that the given value is not selected.

Parameters

string $selector
string $value

Return Value

$this

$this seeIsChecked(string $selector, bool $negate = false)

Assert that the given checkbox is selected.

Parameters

string $selector
bool $negate

Return Value

$this

$this dontSeeIsChecked(string $selector)

Assert that the given checkbox is not selected.

Parameters

string $selector

Return Value

$this

protected $this click(string $name)

Click a link with the given body, name, or ID attribute.

Parameters

string $name

Return Value

$this

Exceptions

InvalidArgumentException

protected $this type(string $text, string $element)

Fill an input field with the given text.

Parameters

string $text
string $element

Return Value

$this

protected $this check(string $element)

Check a checkbox on the page.

Parameters

string $element

Return Value

$this

protected $this uncheck(string $element)

Uncheck a checkbox on the page.

Parameters

string $element

Return Value

$this

protected $this select(string $option, string $element)

Select an option from a drop-down.

Parameters

string $option
string $element

Return Value

$this

protected $this attach(string $absolutePath, string $element)

Attach a file to a form field on the page.

Parameters

string $absolutePath
string $element

Return Value

$this

protected $this press(string $buttonText)

Submit a form using the button with the given text value.

Parameters

string $buttonText

Return Value

$this

protected $this submitForm(string $buttonText, array $inputs = [], array $uploads = [])

Submit a form on the page with the given input.

Parameters

string $buttonText
array $inputs
array $uploads

Return Value

$this

protected Form fillForm(string $buttonText, array $inputs = [])

Fill the form with the given data.

Parameters

string $buttonText
array $inputs

Return Value

Form

protected Form getForm(string|null $buttonText = null)

Get the form from the page with the given submit button text.

Parameters

string|null $buttonText

Return Value

Form

Exceptions

InvalidArgumentException

protected $this storeInput(string $element, string $text)

Store a form input in the local array.

Parameters

string $element
string $text

Return Value

$this

protected $this assertFilterProducesResults(string $filter)

Assert that a filtered Crawler returns nodes.

Parameters

string $filter

Return Value

$this

Exceptions

InvalidArgumentException

protected Crawler filterByNameOrId(string $name, array|string $elements = '*')

Filter elements according to the given name or ID attribute.

Parameters

string $name
array|string $elements

Return Value

Crawler

protected array convertUploadsForTesting(Form $form, array $uploads)

Convert the given uploads to UploadedFile instances.

Parameters

Form $form
array $uploads

Return Value

array

protected prepareArrayBasedFileInput(array $uploads, string $key, mixed $file)

Store an array based file upload with the proper nested array structure.

Parameters

array $uploads
string $key
mixed $file

protected UploadedFile getUploadedFileForTesting(array $file, array $uploads, string $name)

Create an UploadedFile instance for testing.

Parameters

array $file
array $uploads
string $name

Return Value

UploadedFile

$this withoutMiddleware()

Disable middleware for the test.

Return Value

$this

$this json(string $method, string $uri, array $data = [], array $headers = [])

Visit the given URI with a JSON request.

Parameters

string $method
string $uri
array $data
array $headers

Return Value

$this

protected array extractFilesFromDataArray(array $data)

Extract the file uploads from the given data array.

Parameters

array $data

Return Value

array

$this get(string $uri, array $headers = [])

Visit the given URI with a GET request.

Parameters

string $uri
array $headers

Return Value

$this

$this getJson(string $uri, array $headers = [])

Visit the given URI with a GET request, expecting a JSON response.

Parameters

string $uri
array $headers

Return Value

$this

$this post(string $uri, array $data = [], array $headers = [])

Visit the given URI with a POST request.

Parameters

string $uri
array $data
array $headers

Return Value

$this

$this postJson(string $uri, array $data = [], array $headers = [])

Visit the given URI with a POST request, expecting a JSON response.

Parameters

string $uri
array $data
array $headers

Return Value

$this

$this put(string $uri, array $data = [], array $headers = [])

Visit the given URI with a PUT request.

Parameters

string $uri
array $data
array $headers

Return Value

$this

$this putJson(string $uri, array $data = [], array $headers = [])

Visit the given URI with a PUT request, expecting a JSON response.

Parameters

string $uri
array $data
array $headers

Return Value

$this

$this patch(string $uri, array $data = [], array $headers = [])

Visit the given URI with a PATCH request.

Parameters

string $uri
array $data
array $headers

Return Value

$this

$this patchJson(string $uri, array $data = [], array $headers = [])

Visit the given URI with a PATCH request, expecting a JSON response.

Parameters

string $uri
array $data
array $headers

Return Value

$this

$this delete(string $uri, array $data = [], array $headers = [])

Visit the given URI with a DELETE request.

Parameters

string $uri
array $data
array $headers

Return Value

$this

$this deleteJson(string $uri, array $data = [], array $headers = [])

Visit the given URI with a DELETE request, expecting a JSON response.

Parameters

string $uri
array $data
array $headers

Return Value

$this

$this handle(Request $request)

Send the given request through the application.

This method allows you to fully customize the entire Request object.

Parameters

Request $request

Return Value

$this

protected $this shouldReturnJson(array $data = null)

Assert that the response contains JSON.

Parameters

array $data

Return Value

$this

protected $this|null receiveJson(array $data = null)

Assert that the response contains JSON.

Parameters

array $data

Return Value

$this|null

$this seeJsonEquals(array $data)

Assert that the response contains an exact JSON array.

Parameters

array $data

Return Value

$this

$this seeJson(array $data = null, bool $negate = false)

Assert that the response contains JSON.

Parameters

array $data
bool $negate

Return Value

$this

$this dontSeeJson(array $data = null)

Assert that the response doesn't contain JSON.

Parameters

array $data

Return Value

$this

$this seeJsonStructure(array $structure = null, array|null $responseData = null)

Assert that the JSON response has a given structure.

Parameters

array $structure
array|null $responseData

Return Value

$this

protected $this seeJsonContains(array $data, bool $negate = false)

Assert that the response contains the given JSON.

Parameters

array $data
bool $negate

Return Value

$this

protected $this seeJsonSubset(array $data)

Assert that the response is a superset of the given JSON.

Parameters

array $data

Return Value

$this

protected array decodeResponseJson()

Validate and return the decoded response JSON.

Return Value

array

protected string formatToExpectedJson(string $key, mixed $value)

Format the given key and value into a JSON string for expectation checks.

Parameters

string $key
mixed $value

Return Value

string

protected $this seeStatusCode(int $status)

Asserts that the status code of the response matches the given code.

Parameters

int $status

Return Value

$this

protected $this seeHeader(string $headerName, mixed $value = null)

Asserts that the response contains the given header and equals the optional value.

Parameters

string $headerName
mixed $value

Return Value

$this

protected $this seePlainCookie(string $cookieName, mixed $value = null)

Asserts that the response contains the given cookie and equals the optional value.

Parameters

string $cookieName
mixed $value

Return Value

$this

protected $this seeCookie(string $cookieName, mixed $value = null, bool $encrypted = true)

Asserts that the response contains the given cookie and equals the optional value.

Parameters

string $cookieName
mixed $value
bool $encrypted

Return Value

$this

protected $this withServerVariables(array $server)

Define a set of server variables to be sent with the requests.

Parameters

array $server

Return Value

$this

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.

Parameters

string $method
string $uri
array $parameters
array $cookies
array $files
array $server
string $content

Return Value

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.

Parameters

string $method
string $uri
array $parameters
array $cookies
array $files
array $server
string $content

Return Value

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.

Parameters

string $method
string $action
array $wildcards
array $parameters
array $cookies
array $files
array $server
string $content

Return Value

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.

Parameters

string $method
string $name
array $routeParameters
array $parameters
array $cookies
array $files
array $server
string $content

Return Value

Response

protected string prepareUrlForRequest(string $uri)

Turn the given URI into a fully qualified URL.

Parameters

string $uri

Return Value

string

protected array transformHeadersToServerVars(array $headers)

Transform headers array to array of $SERVER vars with HTTP* format.

Parameters

array $headers

Return Value

array

protected mixed filterFiles(array $files)

Filter the given array of files, removing any empty values.

Parameters

array $files

Return Value

mixed

$this assertResponseOk()

Assert that the client response has an OK status code.

Return Value

$this

$this assertResponseStatus(int $code)

Assert that the client response has a given code.

Parameters

int $code

Return Value

$this

$this assertViewHas(string|array $key, mixed $value = null)

Assert that the response view has a given piece of bound data.

Parameters

string|array $key
mixed $value

Return Value

$this

$this assertViewHasAll(array $bindings)

Assert that the view has a given list of bound data.

Parameters

array $bindings

Return Value

$this

$this assertViewMissing(string $key)

Assert that the response view is missing a piece of bound data.

Parameters

string $key

Return Value

$this

$this assertRedirectedTo(string $uri, array $with = [])

Assert whether the client was redirected to a given URI.

Parameters

string $uri
array $with

Return Value

$this

$this assertRedirectedToRoute(string $name, array $parameters = [], array $with = [])

Assert whether the client was redirected to a given route.

Parameters

string $name
array $parameters
array $with

Return Value

$this

$this assertRedirectedToAction(string $name, array $parameters = [], array $with = [])

Assert whether the client was redirected to a given action.

Parameters

string $name
array $parameters
array $with

Return Value

$this

void dump()

Dump the content from the last response.

Return Value

void

$this actingAs(Authenticatable $user, string|null $driver = null)

Set the currently logged in user for the application.

Parameters

Authenticatable $user
string|null $driver

Return Value

$this

$this be(Authenticatable $user, string|null $driver = null)

Set the currently logged in user for the application.

Parameters

Authenticatable $user
string|null $driver

Return Value

$this

$this seeIsAuthenticated(string|null $guard = null)

Assert that the user is authenticated.

Parameters

string|null $guard

Return Value

$this

$this dontSeeIsAuthenticated(string|null $guard = null)

Assert that the user is not authenticated.

Parameters

string|null $guard

Return Value

$this

protected bool isAuthenticated(string|null $guard = null)

Return true if the user is authenticated, false otherwise.

Parameters

string|null $guard

Return Value

bool

$this seeIsAuthenticatedAs($user, string|null $guard = null)

Assert that the user is authenticated as the given user.

Parameters

$user
string|null $guard

Return Value

$this

$this seeCredentials(array $credentials, string|null $guard = null)

Assert that the given credentials are valid.

Parameters

array $credentials
string|null $guard

Return Value

$this

$this dontSeeCredentials(array $credentials, string|null $guard = null)

Assert that the given credentials are invalid.

Parameters

array $credentials
string|null $guard

Return Value

$this

protected bool hasCredentials(array $credentials, string|null $guard = null)

Return true is the credentials are valid, false otherwise.

Parameters

array $credentials
string|null $guard

Return Value

bool

int artisan(string $command, array $parameters = [])

Call artisan command and return code.

Parameters

string $command
array $parameters

Return Value

int

protected $this seeInDatabase(string $table, array $data, string $connection = null)

Assert that a given where condition exists in the database.

Parameters

string $table
array $data
string $connection

Return Value

$this

protected $this missingFromDatabase(string $table, array $data, string $connection = null)

Assert that a given where condition does not exist in the database.

Parameters

string $table
array $data
string $connection

Return Value

$this

protected $this dontSeeInDatabase(string $table, array $data, string $connection = null)

Assert that a given where condition does not exist in the database.

Parameters

string $table
array $data
string $connection

Return Value

$this

protected $this notSeeInDatabase(string $table, array $data, string $connection = null)

Assert that a given where condition does not exist in the database.

Parameters

string $table
array $data
string $connection

Return Value

$this

$this seed(string $class = 'DatabaseSeeder')

Seed a given database connection.

Parameters

string $class

Return Value

$this

$this withSession(array $data)

Set the session to the given array.

Parameters

array $data

Return Value

$this

$this session(array $data)

Set the session to the given array.

Parameters

array $data

Return Value

$this

protected $this startSession()

Start the session for the application.

Return Value

$this

$this flushSession()

Flush all of the current session data.

Return Value

$this

$this seeInSession(string|array $key, mixed $value = null)

Assert that the session has a given value.

Parameters

string|array $key
mixed $value

Return Value

$this

$this assertSessionHas(string|array $key, mixed $value = null)

Assert that the session has a given value.

Parameters

string|array $key
mixed $value

Return Value

$this

$this assertSessionHasAll(array $bindings)

Assert that the session has a given list of values.

Parameters

array $bindings

Return Value

$this

$this assertSessionMissing(string|array $key)

Assert that the session does not have a given key.

Parameters

string|array $key

Return Value

$this

$this assertSessionHasErrors(string|array $bindings = [], mixed $format = null)

Assert that the session has errors bound.

Parameters

string|array $bindings
mixed $format

Return Value

$this

$this assertHasOldInput()

Assert that the session has old input.

Return Value

$this

$this expectsEvents(array|string $events)

Specify a list of events that should be fired for the given operation.

These events will be mocked, so that handlers will not actually be executed.

Parameters

array|string $events

Return Value

$this

Exceptions

Exception

$this doesntExpectEvents(array|string $events)

Specify a list of events that should not be fired for the given operation.

These events will be mocked, so that handlers will not actually be executed.

Parameters

array|string $events

Return Value

$this

protected $this withoutEvents()

Mock the event dispatcher so all events are silenced and collected.

Return Value

$this

$this expectsModelEvents(string $model, array|string $events)

Specify a list of events that should be fired for the given operation.

These events will be mocked, so that handlers will not actually be executed.

Parameters

string $model
array|string $events

Return Value

$this

Exceptions

Exception

$this doesntExpectModelEvents(string $model, array|string $events)

Specify a list of events that should not be fired for the given operation.

These events will be mocked, so that handlers will not actually be executed.

Parameters

string $model
array|string $events

Return Value

$this

Exceptions

Exception

protected $this withoutModelEvents()

Mock the model event dispatcher so all Eloquent events are silenced.

Return Value

$this

$this withoutObservers(array|string $observers)

Specify a list of observers that will not run for the given operation.

Parameters

array|string $observers

Return Value

$this

protected array getFiredEvents(array $events)

Filter the given events against the fired events.

Parameters

array $events

Return Value

array

protected array getFiredModelEvents(array $events)

Filter the given events against the fired events.

Parameters

array $events

Return Value

array

protected $this expectsJobs(array|string $jobs)

Specify a list of jobs that should be dispatched for the given operation.

These jobs will be mocked, so that handlers will not actually be executed.

Parameters

array|string $jobs

Return Value

$this

protected $this doesntExpectJobs(array|string $jobs)

Specify a list of jobs that should not be dispatched for the given operation.

These jobs will be mocked, so that handlers will not actually be executed.

Parameters

array|string $jobs

Return Value

$this

protected $this withoutJobs()

Mock the job dispatcher so all jobs are silenced and collected.

Return Value

$this

protected array getDispatchedJobs(array $jobs)

Filter the given jobs against the dispatched jobs.

Parameters

array $jobs

Return Value

array

protected array getDispatched(array $classes, array $dispatched)

Filter the given classes against an array of dispatched classes.

Parameters

array $classes
array $dispatched

Return Value

array

protected bool wasDispatched(string $needle, array $haystack)

Check if the given class exists in an array of dispatched classes.

Parameters

string $needle
array $haystack

Return Value

bool

protected $this withoutNotifications()

Mock the notification dispatcher so all notifications are silenced.

Return Value

$this

protected $this expectsNotification(mixed $notifiable, string $notification)

Specify a notification that is expected to be dispatched.

Parameters

mixed $notifiable
string $notification

Return Value

$this

abstract HttpKernelInterface createApplication()

Creates the application.

Needs to be implemented by subclasses.

Return Value

HttpKernelInterface

protected void setUp()

Setup the test environment.

Return Value

void

protected void refreshApplication()

Refresh the application instance.

Return Value

void

protected void setUpTraits()

Boot the testing helper traits.

Return Value

void

protected void tearDown()

Clean up the testing environment before the next test.

Return Value

void

void afterApplicationCreated(callable $callback)

Register a callback to be run after the application is created.

Parameters

callable $callback

Return Value

void

protected void beforeApplicationDestroyed(callable $callback)

Register a callback to be run before the application is destroyed.

Parameters

callable $callback

Return Value

void

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.3/Illuminate/Foundation/Testing/TestCase.html