abstract class TestCase extends TestCase

Traits

Properties

protected array $serverVariables

Additional server variables for the request.

from  MakesHttpRequests
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
swap(string $abstract, object $instance)

Register an instance of an object in the container.

object
instance(string $abstract, object $instance)

Register an instance of an object in the container.

$this
withServerVariables(array $server)

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

$this
withoutMiddleware()

Disable middleware for the test.

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

Visit the given URI with a GET request.

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

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

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

Visit the given URI with a POST request.

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

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

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

Visit the given URI with a PUT request.

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

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

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

Visit the given URI with a PATCH request.

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

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

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

Visit the given URI with a DELETE request.

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

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

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

Call the given URI with a JSON request.

call(string $method, string $uri, array $parameters = [], array $cookies = [], array $files = [], array $server = [], string $content = null)

Call the given URI 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.

string
formatServerHeaderKey(string $name)

Format the header name for the server array.

array
extractFilesFromDataArray(array $data)

Extract the file uploads from the given data array.

createTestResponse(Response $response)

Create the test response instance from the given response.

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

Set the currently logged in user for the application.

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

Set the currently logged in user for the application.

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

Assert that the user is authenticated.

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

Assert that the user is not authenticated.

bool
isAuthenticated(string|null $guard = null)

Return true if the user is authenticated, false otherwise.

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

Assert that the user is authenticated as the given user.

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

Assert that the given credentials are valid.

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

Assert that the given credentials are invalid.

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

Return true if the credentials are valid, false otherwise.

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

Call artisan command and return code.

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

Assert that a given where condition exists in the database.

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

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

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

Assert the given record has been deleted.

getConnection(string|null $connection = null)

Get the database connection.

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

Seed a given database connection.

$this
withSession(array $data)

Set the session to the given array.

$this
session(array $data)

Set the session to the given array.

$this
startSession()

Start the session for the application.

$this
flushSession()

Flush all of the current session data.

$this
expectsEvents(array|string $events)

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

$this
doesntExpectEvents(array|string $events)

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

$this
withoutEvents()

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

array
getFiredEvents(array $events)

Filter the given events against the fired events.

$this
expectsJobs(array|string $jobs)

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

$this
doesntExpectJobs(array|string $jobs)

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

$this
withoutJobs()

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

array
getDispatchedJobs(array $jobs)

Filter the given jobs against the dispatched jobs.

array
getDispatched(array $classes, array $dispatched)

Filter the given classes against an array of dispatched classes.

bool
wasDispatched(string $needle, array $haystack)

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

$this
withoutNotifications()

Mock the notification dispatcher so all notifications are silenced.

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

Specify a notification that is expected to be dispatched.

HttpKernelInterface
createApplication()

Creates the application.

void
setUp()

Setup the test environment.

void
refreshApplication()

Refresh the application instance.

array
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 swap(string $abstract, object $instance)

Register an instance of an object in the container.

Parameters

string $abstract
object $instance

Return Value

object

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

Register an instance of an object in the container.

Parameters

string $abstract
object $instance

Return Value

object

in MakesHttpRequests at line 27
$this withServerVariables(array $server)

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

Parameters

array $server

Return Value

$this

in MakesHttpRequests at line 39
$this withoutMiddleware()

Disable middleware for the test.

Return Value

$this

in MakesHttpRequests at line 53
TestResponse get(string $uri, array $headers = [])

Visit the given URI with a GET request.

Parameters

string $uri
array $headers

Return Value

TestResponse

in MakesHttpRequests at line 67
TestResponse getJson(string $uri, array $headers = [])

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

Parameters

string $uri
array $headers

Return Value

TestResponse

in MakesHttpRequests at line 80
TestResponse post(string $uri, array $data = [], array $headers = [])

Visit the given URI with a POST request.

Parameters

string $uri
array $data
array $headers

Return Value

TestResponse

in MakesHttpRequests at line 95
TestResponse 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

TestResponse

in MakesHttpRequests at line 108
TestResponse put(string $uri, array $data = [], array $headers = [])

Visit the given URI with a PUT request.

Parameters

string $uri
array $data
array $headers

Return Value

TestResponse

in MakesHttpRequests at line 123
TestResponse 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

TestResponse

in MakesHttpRequests at line 136
TestResponse patch(string $uri, array $data = [], array $headers = [])

Visit the given URI with a PATCH request.

Parameters

string $uri
array $data
array $headers

Return Value

TestResponse

in MakesHttpRequests at line 151
TestResponse 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

TestResponse

in MakesHttpRequests at line 164
TestResponse delete(string $uri, array $data = [], array $headers = [])

Visit the given URI with a DELETE request.

Parameters

string $uri
array $data
array $headers

Return Value

TestResponse

in MakesHttpRequests at line 179
TestResponse 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

TestResponse

in MakesHttpRequests at line 193
TestResponse json(string $method, string $uri, array $data = [], array $headers = [])

Call the given URI with a JSON request.

Parameters

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

Return Value

TestResponse

in MakesHttpRequests at line 222
TestResponse 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

TestResponse

in MakesHttpRequests at line 248
protected string prepareUrlForRequest(string $uri)

Turn the given URI into a fully qualified URL.

Parameters

string $uri

Return Value

string

in MakesHttpRequests at line 267
protected array transformHeadersToServerVars(array $headers)

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

Parameters

array $headers

Return Value

array

in MakesHttpRequests at line 282
protected string formatServerHeaderKey(string $name)

Format the header name for the server array.

Parameters

string $name

Return Value

string

in MakesHttpRequests at line 297
protected array extractFilesFromDataArray(array $data)

Extract the file uploads from the given data array.

Parameters

array $data

Return Value

array

in MakesHttpRequests at line 324
protected TestResponse createTestResponse(Response $response)

Create the test response instance from the given response.

Parameters

Response $response

Return Value

TestResponse

$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

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

Set the currently logged in user for the application.

Parameters

Authenticatable $user
string|null $driver

Return Value

void

$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 if 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 assertDatabaseHas(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 assertDatabaseMissing(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 assertSoftDeleted(string $table, array $data, string $connection = null)

Assert the given record has been deleted.

Parameters

string $table
array $data
string $connection

Return Value

$this

protected Connection getConnection(string|null $connection = null)

Get the database connection.

Parameters

string|null $connection

Return Value

Connection

$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 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

protected array getFiredEvents(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

at line 56
abstract HttpKernelInterface createApplication()

Creates the application.

Needs to be implemented by subclasses.

Return Value

HttpKernelInterface

at line 63
protected void setUp()

Setup the test environment.

Return Value

void

at line 87
protected void refreshApplication()

Refresh the application instance.

Return Value

void

at line 97
protected array setUpTraits()

Boot the testing helper traits.

Return Value

array

at line 125
protected void tearDown()

Clean up the testing environment before the next test.

Return Value

void

at line 159
void afterApplicationCreated(callable $callback)

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

Parameters

callable $callback

Return Value

void

at line 174
protected void beforeApplicationDestroyed(callable $callback)

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

Parameters

callable $callback

Return Value

void