Documentation

TestCase extends TestCase
in package
Uses InteractsWithContainer, MakesHttpRequests, InteractsWithAuthentication, InteractsWithConsole, InteractsWithDatabase, InteractsWithExceptionHandling, InteractsWithSession, MocksApplicationServices

Table of Contents

$afterApplicationCreatedCallbacks  : array<string|int, mixed>
The callbacks that should be run after the application is created.
$app  : Application
The Illuminate application instance.
$beforeApplicationDestroyedCallbacks  : array<string|int, mixed>
The callbacks that should be run before the application is destroyed.
$defaultHeaders  : array<string|int, mixed>
Additional headers for the request.
$dispatchedJobs  : array<string|int, mixed>
All of the dispatched jobs.
$dispatchedNotifications  : array<string|int, mixed>
All of the dispatched notifications.
$firedEvents  : array<string|int, mixed>
All of the fired events.
$firedModelEvents  : array<string|int, mixed>
All of the fired model events.
$followRedirects  : bool
Indicates whether redirects should be followed.
$originalExceptionHandler  : ExceptionHandler|null
The original exception handler.
$serverVariables  : array<string|int, mixed>
Additional server variables for the request.
$setUpHasRun  : bool
Indicates if we have made it through the base setUp function.
actingAs()  : $this
Set the currently logged in user for the application.
afterApplicationCreated()  : void
Register a callback to be run after the application is created.
artisan()  : int
Call artisan command and return code.
assertAuthenticated()  : $this
Assert that the user is authenticated.
assertAuthenticatedAs()  : $this
Assert that the user is authenticated as the given user.
assertCredentials()  : $this
Assert that the given credentials are valid.
assertGuest()  : $this
Assert that the user is not authenticated.
assertInvalidCredentials()  : $this
Assert that the given credentials are invalid.
be()  : void
Set the currently logged in user for the application.
call()  : TestResponse
Call the given URI and return the Response.
createApplication()  : HttpKernelInterface
Creates the application.
delete()  : TestResponse
Visit the given URI with a DELETE request.
deleteJson()  : TestResponse
Visit the given URI with a DELETE request, expecting a JSON response.
doesntExpectEvents()  : $this
Specify a list of events that should not be fired for the given operation.
expectsEvents()  : $this
Specify a list of events that should be fired for the given operation.
flushHeaders()  : $this
Flush all the configured headers.
flushSession()  : $this
Flush all of the current session data.
followingRedirects()  : $this
Automatically follow any redirects returned from the response.
from()  : $this
Set the referer header to simulate a previous request.
get()  : TestResponse
Visit the given URI with a GET request.
getJson()  : TestResponse
Visit the given URI with a GET request, expecting a JSON response.
json()  : TestResponse
Call the given URI with a JSON request.
patch()  : TestResponse
Visit the given URI with a PATCH request.
patchJson()  : TestResponse
Visit the given URI with a PATCH request, expecting a JSON response.
post()  : TestResponse
Visit the given URI with a POST request.
postJson()  : TestResponse
Visit the given URI with a POST request, expecting a JSON response.
put()  : TestResponse
Visit the given URI with a PUT request.
putJson()  : TestResponse
Visit the given URI with a PUT request, expecting a JSON response.
seed()  : $this
Seed a given database connection.
session()  : $this
Set the session to the given array.
withHeader()  : $this
Add a header to be sent with the request.
withHeaders()  : $this
Define additional headers to be sent with the request.
withMiddleware()  : $this
Enable the given middleware for the test.
withoutMiddleware()  : $this
Disable middleware for the test.
withServerVariables()  : $this
Define a set of server variables to be sent with the requests.
withSession()  : $this
Set the session to the given array.
assertDatabaseHas()  : $this
Assert that a given where condition exists in the database.
assertDatabaseMissing()  : $this
Assert that a given where condition does not exist in the database.
assertSoftDeleted()  : $this
Assert the given record has been deleted.
beforeApplicationDestroyed()  : void
Register a callback to be run before the application is destroyed.
createTestResponse()  : TestResponse
Create the test response instance from the given response.
doesntExpectJobs()  : $this
Specify a list of jobs that should not be dispatched for the given operation.
expectsJobs()  : $this
Specify a list of jobs that should be dispatched for the given operation.
expectsNotification()  : $this
Specify a notification that is expected to be dispatched.
extractFilesFromDataArray()  : array<string|int, mixed>
Extract the file uploads from the given data array.
followRedirects()  : Response
Follow a redirect chain until a non-redirect is received.
formatServerHeaderKey()  : string
Format the header name for the server array.
getConnection()  : Connection
Get the database connection.
getDispatched()  : array<string|int, mixed>
Filter the given classes against an array of dispatched classes.
getDispatchedJobs()  : array<string|int, mixed>
Filter the given jobs against the dispatched jobs.
getFiredEvents()  : array<string|int, mixed>
Filter the given events against the fired events.
handleExceptions()  : $this
Only handle the given exceptions via the exception handler.
handleValidationExceptions()  : $this
Only handle validation exceptions via the exception handler.
hasCredentials()  : bool
Return true if the credentials are valid, false otherwise.
instance()  : object
Register an instance of an object in the container.
isAuthenticated()  : bool
Return true if the user is authenticated, false otherwise.
prepareUrlForRequest()  : string
Turn the given URI into a fully qualified URL.
refreshApplication()  : void
Refresh the application instance.
setUp()  : void
Setup the test environment.
setUpTraits()  : array<string|int, mixed>
Boot the testing helper traits.
startSession()  : $this
Start the session for the application.
swap()  : object
Register an instance of an object in the container.
tearDown()  : void
Clean up the testing environment before the next test.
transformHeadersToServerVars()  : array<string|int, mixed>
Transform headers array to array of $_SERVER vars with HTTP_* format.
wasDispatched()  : bool
Check if the given class exists in an array of dispatched classes.
withExceptionHandling()  : $this
Restore exception handling.
withoutEvents()  : $this
Mock the event dispatcher so all events are silenced and collected.
withoutExceptionHandling()  : $this
Disable exception handling for the test.
withoutJobs()  : $this
Mock the job dispatcher so all jobs are silenced and collected.
withoutNotifications()  : $this
Mock the notification dispatcher so all notifications are silenced.

Properties

$afterApplicationCreatedCallbacks

The callbacks that should be run after the application is created.

protected array<string|int, mixed> $afterApplicationCreatedCallbacks = []

$beforeApplicationDestroyedCallbacks

The callbacks that should be run before the application is destroyed.

protected array<string|int, mixed> $beforeApplicationDestroyedCallbacks = []

$defaultHeaders

Additional headers for the request.

protected array<string|int, mixed> $defaultHeaders = []

$dispatchedNotifications

All of the dispatched notifications.

protected array<string|int, mixed> $dispatchedNotifications = []

$firedModelEvents

All of the fired model events.

protected array<string|int, mixed> $firedModelEvents = []

$followRedirects

Indicates whether redirects should be followed.

protected bool $followRedirects = false

$serverVariables

Additional server variables for the request.

protected array<string|int, mixed> $serverVariables = []

$setUpHasRun

Indicates if we have made it through the base setUp function.

protected bool $setUpHasRun = false

Methods

afterApplicationCreated()

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

public afterApplicationCreated(callable $callback) : void
Parameters
$callback : callable
Return values
void

artisan()

Call artisan command and return code.

public artisan(string $command[, array<string|int, mixed> $parameters = [] ]) : int
Parameters
$command : string
$parameters : array<string|int, mixed> = []
Return values
int

assertAuthenticated()

Assert that the user is authenticated.

public assertAuthenticated([string|null $guard = null ]) : $this
Parameters
$guard : string|null = null
Return values
$this

assertCredentials()

Assert that the given credentials are valid.

public assertCredentials(array<string|int, mixed> $credentials[, string|null $guard = null ]) : $this
Parameters
$credentials : array<string|int, mixed>
$guard : string|null = null
Return values
$this

assertGuest()

Assert that the user is not authenticated.

public assertGuest([string|null $guard = null ]) : $this
Parameters
$guard : string|null = null
Return values
$this

assertInvalidCredentials()

Assert that the given credentials are invalid.

public assertInvalidCredentials(array<string|int, mixed> $credentials[, string|null $guard = null ]) : $this
Parameters
$credentials : array<string|int, mixed>
$guard : string|null = null
Return values
$this

call()

Call the given URI and return the Response.

public call(string $method, string $uri[, array<string|int, mixed> $parameters = [] ][, array<string|int, mixed> $cookies = [] ][, array<string|int, mixed> $files = [] ][, array<string|int, mixed> $server = [] ][, string $content = null ]) : TestResponse
Parameters
$method : string
$uri : string
$parameters : array<string|int, mixed> = []
$cookies : array<string|int, mixed> = []
$files : array<string|int, mixed> = []
$server : array<string|int, mixed> = []
$content : string = null
Return values
TestResponse

delete()

Visit the given URI with a DELETE request.

public delete(string $uri[, array<string|int, mixed> $data = [] ][, array<string|int, mixed> $headers = [] ]) : TestResponse
Parameters
$uri : string
$data : array<string|int, mixed> = []
$headers : array<string|int, mixed> = []
Return values
TestResponse

deleteJson()

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

public deleteJson(string $uri[, array<string|int, mixed> $data = [] ][, array<string|int, mixed> $headers = [] ]) : TestResponse
Parameters
$uri : string
$data : array<string|int, mixed> = []
$headers : array<string|int, mixed> = []
Return values
TestResponse

doesntExpectEvents()

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

public doesntExpectEvents(array<string|int, mixed>|string $events) : $this

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

Parameters
$events : array<string|int, mixed>|string
Return values
$this

expectsEvents()

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

public expectsEvents(array<string|int, mixed>|string $events) : $this

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

Parameters
$events : array<string|int, mixed>|string
Tags
throws
Exception
Return values
$this

flushHeaders()

Flush all the configured headers.

public flushHeaders() : $this
Return values
$this

flushSession()

Flush all of the current session data.

public flushSession() : $this
Return values
$this

followingRedirects()

Automatically follow any redirects returned from the response.

public followingRedirects() : $this
Return values
$this

from()

Set the referer header to simulate a previous request.

public from(string $url) : $this
Parameters
$url : string
Return values
$this

get()

Visit the given URI with a GET request.

public get(string $uri[, array<string|int, mixed> $headers = [] ]) : TestResponse
Parameters
$uri : string
$headers : array<string|int, mixed> = []
Return values
TestResponse

getJson()

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

public getJson(string $uri[, array<string|int, mixed> $headers = [] ]) : TestResponse
Parameters
$uri : string
$headers : array<string|int, mixed> = []
Return values
TestResponse

json()

Call the given URI with a JSON request.

public json(string $method, string $uri[, array<string|int, mixed> $data = [] ][, array<string|int, mixed> $headers = [] ]) : TestResponse
Parameters
$method : string
$uri : string
$data : array<string|int, mixed> = []
$headers : array<string|int, mixed> = []
Return values
TestResponse

patch()

Visit the given URI with a PATCH request.

public patch(string $uri[, array<string|int, mixed> $data = [] ][, array<string|int, mixed> $headers = [] ]) : TestResponse
Parameters
$uri : string
$data : array<string|int, mixed> = []
$headers : array<string|int, mixed> = []
Return values
TestResponse

patchJson()

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

public patchJson(string $uri[, array<string|int, mixed> $data = [] ][, array<string|int, mixed> $headers = [] ]) : TestResponse
Parameters
$uri : string
$data : array<string|int, mixed> = []
$headers : array<string|int, mixed> = []
Return values
TestResponse

post()

Visit the given URI with a POST request.

public post(string $uri[, array<string|int, mixed> $data = [] ][, array<string|int, mixed> $headers = [] ]) : TestResponse
Parameters
$uri : string
$data : array<string|int, mixed> = []
$headers : array<string|int, mixed> = []
Return values
TestResponse

postJson()

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

public postJson(string $uri[, array<string|int, mixed> $data = [] ][, array<string|int, mixed> $headers = [] ]) : TestResponse
Parameters
$uri : string
$data : array<string|int, mixed> = []
$headers : array<string|int, mixed> = []
Return values
TestResponse

put()

Visit the given URI with a PUT request.

public put(string $uri[, array<string|int, mixed> $data = [] ][, array<string|int, mixed> $headers = [] ]) : TestResponse
Parameters
$uri : string
$data : array<string|int, mixed> = []
$headers : array<string|int, mixed> = []
Return values
TestResponse

putJson()

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

public putJson(string $uri[, array<string|int, mixed> $data = [] ][, array<string|int, mixed> $headers = [] ]) : TestResponse
Parameters
$uri : string
$data : array<string|int, mixed> = []
$headers : array<string|int, mixed> = []
Return values
TestResponse

seed()

Seed a given database connection.

public seed([string $class = 'DatabaseSeeder' ]) : $this
Parameters
$class : string = 'DatabaseSeeder'
Return values
$this

session()

Set the session to the given array.

public session(array<string|int, mixed> $data) : $this
Parameters
$data : array<string|int, mixed>
Return values
$this

withHeader()

Add a header to be sent with the request.

public withHeader(string $name, string $value) : $this
Parameters
$name : string
$value : string
Return values
$this

withHeaders()

Define additional headers to be sent with the request.

public withHeaders(array<string|int, mixed> $headers) : $this
Parameters
$headers : array<string|int, mixed>
Return values
$this

withMiddleware()

Enable the given middleware for the test.

public withMiddleware([string|array<string|int, mixed> $middleware = null ]) : $this
Parameters
$middleware : string|array<string|int, mixed> = null
Return values
$this

withoutMiddleware()

Disable middleware for the test.

public withoutMiddleware([string|array<string|int, mixed> $middleware = null ]) : $this
Parameters
$middleware : string|array<string|int, mixed> = null
Return values
$this

withServerVariables()

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

public withServerVariables(array<string|int, mixed> $server) : $this
Parameters
$server : array<string|int, mixed>
Return values
$this

withSession()

Set the session to the given array.

public withSession(array<string|int, mixed> $data) : $this
Parameters
$data : array<string|int, mixed>
Return values
$this

assertDatabaseHas()

Assert that a given where condition exists in the database.

protected assertDatabaseHas(string $table, array<string|int, mixed> $data[, string $connection = null ]) : $this
Parameters
$table : string
$data : array<string|int, mixed>
$connection : string = null
Return values
$this

assertDatabaseMissing()

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

protected assertDatabaseMissing(string $table, array<string|int, mixed> $data[, string $connection = null ]) : $this
Parameters
$table : string
$data : array<string|int, mixed>
$connection : string = null
Return values
$this

assertSoftDeleted()

Assert the given record has been deleted.

protected assertSoftDeleted(string $table, array<string|int, mixed> $data[, string $connection = null ]) : $this
Parameters
$table : string
$data : array<string|int, mixed>
$connection : string = null
Return values
$this

beforeApplicationDestroyed()

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

protected beforeApplicationDestroyed(callable $callback) : void
Parameters
$callback : callable
Return values
void

doesntExpectJobs()

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

protected doesntExpectJobs(array<string|int, mixed>|string $jobs) : $this

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

Parameters
$jobs : array<string|int, mixed>|string
Return values
$this

expectsJobs()

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

protected expectsJobs(array<string|int, mixed>|string $jobs) : $this

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

Parameters
$jobs : array<string|int, mixed>|string
Return values
$this

expectsNotification()

Specify a notification that is expected to be dispatched.

protected expectsNotification(mixed $notifiable, string $notification) : $this
Parameters
$notifiable : mixed
$notification : string
Return values
$this

extractFilesFromDataArray()

Extract the file uploads from the given data array.

protected extractFilesFromDataArray(array<string|int, mixed> &$data) : array<string|int, mixed>
Parameters
$data : array<string|int, mixed>
Return values
array<string|int, mixed>

formatServerHeaderKey()

Format the header name for the server array.

protected formatServerHeaderKey(string $name) : string
Parameters
$name : string
Return values
string

getDispatched()

Filter the given classes against an array of dispatched classes.

protected getDispatched(array<string|int, mixed> $classes, array<string|int, mixed> $dispatched) : array<string|int, mixed>
Parameters
$classes : array<string|int, mixed>
$dispatched : array<string|int, mixed>
Return values
array<string|int, mixed>

getDispatchedJobs()

Filter the given jobs against the dispatched jobs.

protected getDispatchedJobs(array<string|int, mixed> $jobs) : array<string|int, mixed>
Parameters
$jobs : array<string|int, mixed>
Return values
array<string|int, mixed>

getFiredEvents()

Filter the given events against the fired events.

protected getFiredEvents(array<string|int, mixed> $events) : array<string|int, mixed>
Parameters
$events : array<string|int, mixed>
Return values
array<string|int, mixed>

handleExceptions()

Only handle the given exceptions via the exception handler.

protected handleExceptions(array<string|int, mixed> $exceptions) : $this
Parameters
$exceptions : array<string|int, mixed>
Return values
$this

handleValidationExceptions()

Only handle validation exceptions via the exception handler.

protected handleValidationExceptions() : $this
Return values
$this

hasCredentials()

Return true if the credentials are valid, false otherwise.

protected hasCredentials(array<string|int, mixed> $credentials[, string|null $guard = null ]) : bool
Parameters
$credentials : array<string|int, mixed>
$guard : string|null = null
Return values
bool

instance()

Register an instance of an object in the container.

protected instance(string $abstract, object $instance) : object
Parameters
$abstract : string
$instance : object
Return values
object

isAuthenticated()

Return true if the user is authenticated, false otherwise.

protected isAuthenticated([string|null $guard = null ]) : bool
Parameters
$guard : string|null = null
Return values
bool

prepareUrlForRequest()

Turn the given URI into a fully qualified URL.

protected prepareUrlForRequest(string $uri) : string
Parameters
$uri : string
Return values
string

refreshApplication()

Refresh the application instance.

protected refreshApplication() : void
Return values
void

setUp()

Setup the test environment.

protected setUp() : void
Return values
void

setUpTraits()

Boot the testing helper traits.

protected setUpTraits() : array<string|int, mixed>
Return values
array<string|int, mixed>

startSession()

Start the session for the application.

protected startSession() : $this
Return values
$this

swap()

Register an instance of an object in the container.

protected swap(string $abstract, object $instance) : object
Parameters
$abstract : string
$instance : object
Return values
object

tearDown()

Clean up the testing environment before the next test.

protected tearDown() : void
Return values
void

transformHeadersToServerVars()

Transform headers array to array of $_SERVER vars with HTTP_* format.

protected transformHeadersToServerVars(array<string|int, mixed> $headers) : array<string|int, mixed>
Parameters
$headers : array<string|int, mixed>
Return values
array<string|int, mixed>

wasDispatched()

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

protected wasDispatched(string $needle, array<string|int, mixed> $haystack) : bool
Parameters
$needle : string
$haystack : array<string|int, mixed>
Return values
bool

withoutEvents()

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

protected withoutEvents() : $this
Return values
$this

withoutExceptionHandling()

Disable exception handling for the test.

protected withoutExceptionHandling([array<string|int, mixed> $except = [] ]) : $this
Parameters
$except : array<string|int, mixed> = []
Return values
$this

withoutJobs()

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

protected withoutJobs() : $this
Return values
$this

withoutNotifications()

Mock the notification dispatcher so all notifications are silenced.

protected withoutNotifications() : $this
Return values
$this

Search results