TestCase
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
Register an instance of an object in the container.
Register an instance of an object in the container.
Define a set of server variables to be sent with the requests.
Visit the given URI with a GET request.
Visit the given URI with a GET request, expecting a JSON response.
Visit the given URI with a POST request.
Visit the given URI with a POST request, expecting a JSON response.
Visit the given URI with a PUT request.
Visit the given URI with a PUT request, expecting a JSON response.
Visit the given URI with a PATCH request.
Visit the given URI with a PATCH request, expecting a JSON response.
Visit the given URI with a DELETE request.
Visit the given URI with a DELETE request, expecting a JSON response.
Call the given URI with a JSON request.
Call the given URI and return the Response.
Turn the given URI into a fully qualified URL.
Transform headers array to array of $SERVER vars with HTTP* format.
Format the header name for the server array.
Extract the file uploads from the given data array.
Set the currently logged in user for the application.
Set the currently logged in user for the application.
Assert that the user is authenticated.
Assert that the user is not authenticated.
Return true if the user is authenticated, false otherwise.
Assert that the user is authenticated as the given user.
Assert that the given credentials are valid.
Assert that the given credentials are invalid.
Return true if the credentials are valid, false otherwise.
Call artisan command and return code.
Assert that a given where condition exists in the database.
Assert that a given where condition does not exist in the database.
Assert the given record has been deleted.
Get the database connection.
Seed a given database connection.
Specify a list of events that should be fired for the given operation.
Specify a list of events that should not be fired for the given operation.
Mock the event dispatcher so all events are silenced and collected.
Filter the given events against the fired events.
Specify a list of jobs that should be dispatched for the given operation.
Specify a list of jobs that should not be dispatched for the given operation.
Mock the job dispatcher so all jobs are silenced and collected.
Filter the given jobs against the dispatched jobs.
Filter the given classes against an array of dispatched classes.
Check if the given class exists in an array of dispatched classes.
Mock the notification dispatcher so all notifications are silenced.
Specify a notification that is expected to be dispatched.
Creates the application.
Setup the test environment.
Refresh the application instance.
Boot the testing helper traits.
Clean up the testing environment before the next test.
Register a callback to be run after the application is created.
Register a callback to be run before the application is destroyed.
Details
in
InteractsWithContainer at line 14
protected object
swap(string $abstract, object $instance)
Register an instance of an object in the container.
in
InteractsWithContainer at line 26
protected object
instance(string $abstract, object $instance)
Register an instance of an object in the container.
in
MakesHttpRequests at line 27
$this
withServerVariables(array $server)
Define a set of server variables to be sent with the requests.
in
MakesHttpRequests at line 39
$this
withoutMiddleware()
Disable middleware for the test.
in
MakesHttpRequests at line 53
TestResponse
get(string $uri, array $headers = [])
Visit the given URI with a GET request.
in
MakesHttpRequests at line 67
TestResponse
getJson(string $uri, array $headers = [])
Visit the given URI with a GET request, expecting a JSON response.
in
MakesHttpRequests at line 80
TestResponse
post(string $uri, array $data = [], array $headers = [])
Visit the given URI with a POST request.
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.
in
MakesHttpRequests at line 108
TestResponse
put(string $uri, array $data = [], array $headers = [])
Visit the given URI with a PUT request.
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.
in
MakesHttpRequests at line 136
TestResponse
patch(string $uri, array $data = [], array $headers = [])
Visit the given URI with a PATCH request.
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.
in
MakesHttpRequests at line 164
TestResponse
delete(string $uri, array $data = [], array $headers = [])
Visit the given URI with a DELETE request.
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.
in
MakesHttpRequests at line 193
TestResponse
json(string $method, string $uri, array $data = [], array $headers = [])
Call the given URI with a JSON request.
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.
in
MakesHttpRequests at line 248
protected string
prepareUrlForRequest(string $uri)
Turn the given URI into a fully qualified URL.
in
MakesHttpRequests at line 267
protected array
transformHeadersToServerVars(array $headers)
Transform headers array to array of $SERVER vars with HTTP* format.
in
MakesHttpRequests at line 282
protected string
formatServerHeaderKey(string $name)
Format the header name for the server array.
in
MakesHttpRequests at line 297
protected array
extractFilesFromDataArray(array $data)
Extract the file uploads from the given data array.
in
MakesHttpRequests at line 324
protected TestResponse
createTestResponse(Response $response)
Create the test response instance from the given response.
in
InteractsWithAuthentication at line 16
$this
actingAs(Authenticatable $user, string|null $driver = null)
Set the currently logged in user for the application.
in
InteractsWithAuthentication at line 30
void
be(Authenticatable $user, string|null $driver = null)
Set the currently logged in user for the application.
in
InteractsWithAuthentication at line 43
$this
seeIsAuthenticated(string|null $guard = null)
Assert that the user is authenticated.
in
InteractsWithAuthentication at line 56
$this
dontSeeIsAuthenticated(string|null $guard = null)
Assert that the user is not authenticated.
in
InteractsWithAuthentication at line 69
protected bool
isAuthenticated(string|null $guard = null)
Return true if the user is authenticated, false otherwise.
in
InteractsWithAuthentication at line 81
$this
seeIsAuthenticatedAs($user, string|null $guard = null)
Assert that the user is authenticated as the given user.
in
InteractsWithAuthentication at line 105
$this
seeCredentials(array $credentials, string|null $guard = null)
Assert that the given credentials are valid.
in
InteractsWithAuthentication at line 121
$this
dontSeeCredentials(array $credentials, string|null $guard = null)
Assert that the given credentials are invalid.
in
InteractsWithAuthentication at line 137
protected bool
hasCredentials(array $credentials, string|null $guard = null)
Return true if the credentials are valid, false otherwise.
in
InteractsWithConsole at line 16
int
artisan(string $command, array $parameters = [])
Call artisan command and return code.
in
InteractsWithDatabase at line 19
protected $this
assertDatabaseHas(string $table, array $data, string $connection = null)
Assert that a given where condition exists in the database.
in
InteractsWithDatabase at line 36
protected $this
assertDatabaseMissing(string $table, array $data, string $connection = null)
Assert that a given where condition does not exist in the database.
in
InteractsWithDatabase at line 55
protected $this
assertSoftDeleted(string $table, array $data, string $connection = null)
Assert the given record has been deleted.
in
InteractsWithDatabase at line 70
protected Connection
getConnection(string|null $connection = null)
Get the database connection.
in
InteractsWithDatabase at line 85
$this
seed(string $class = 'DatabaseSeeder')
Seed a given database connection.
in
InteractsWithSession at line 13
$this
withSession(array $data)
Set the session to the given array.
in
InteractsWithSession at line 26
$this
session(array $data)
Set the session to the given array.
in
InteractsWithSession at line 42
protected $this
startSession()
Start the session for the application.
in
InteractsWithSession at line 56
$this
flushSession()
Flush all of the current session data.
in
MocksApplicationServices at line 50
$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.
in
MocksApplicationServices at line 76
$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.
in
MocksApplicationServices at line 97
protected $this
withoutEvents()
Mock the event dispatcher so all events are silenced and collected.
in
MocksApplicationServices at line 116
protected array
getFiredEvents(array $events)
Filter the given events against the fired events.
in
MocksApplicationServices at line 129
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.
in
MocksApplicationServices at line 155
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.
in
MocksApplicationServices at line 176
protected $this
withoutJobs()
Mock the job dispatcher so all jobs are silenced and collected.
in
MocksApplicationServices at line 197
protected array
getDispatchedJobs(array $jobs)
Filter the given jobs against the dispatched jobs.
in
MocksApplicationServices at line 209
protected array
getDispatched(array $classes, array $dispatched)
Filter the given classes against an array of dispatched classes.
in
MocksApplicationServices at line 223
protected bool
wasDispatched(string $needle, array $haystack)
Check if the given class exists in an array of dispatched classes.
in
MocksApplicationServices at line 240
protected $this
withoutNotifications()
Mock the notification dispatcher so all notifications are silenced.
in
MocksApplicationServices at line 262
protected $this
expectsNotification(mixed $notifiable, string $notification)
Specify a notification that is expected to be dispatched.
at line 56
abstract HttpKernelInterface
createApplication()
Creates the application.
Needs to be implemented by subclasses.
at line 63
protected void
setUp()
Setup the test environment.
at line 87
protected void
refreshApplication()
Refresh the application instance.
at line 97
protected array
setUpTraits()
Boot the testing helper traits.
at line 125
protected void
tearDown()
Clean up the testing environment before the next test.
at line 159
void
afterApplicationCreated(callable $callback)
Register a callback to be run after the application is created.
at line 174
protected void
beforeApplicationDestroyed(callable $callback)
Register a callback to be run before the application is destroyed.