TestCase
abstract class TestCase extends TestCase (View source)
Traits
Properties
protected Mix|null | $originalMix | The original Laravel Mix handler. |
from InteractsWithContainer |
protected array | $defaultHeaders | Additional headers for the request. |
from MakesHttpRequests |
protected array | $defaultCookies | Additional cookies for the request. |
from MakesHttpRequests |
protected array | $unencryptedCookies | Additional cookies will not be encrypted for the request. |
from MakesHttpRequests |
protected array | $serverVariables | Additional server variables for the request. |
from MakesHttpRequests |
protected bool | $followRedirects | Indicates whether redirects should be followed. |
from MakesHttpRequests |
protected bool | $encryptCookies | Indicates whether cookies should be encrypted. |
from MakesHttpRequests |
protected bool | $withCredentials | Indicated whether JSON requests should be performed "with credentials" (cookies). |
from MakesHttpRequests |
bool | $mockConsoleOutput | Indicates if the console output should be mocked. |
from InteractsWithConsole |
array | $expectedOutput | All of the expected output lines. |
from InteractsWithConsole |
array | $unexpectedOutput | All of the output lines that aren't expected to be displayed. |
from InteractsWithConsole |
array | $expectedTables | All of the expected output tables. |
from InteractsWithConsole |
array | $expectedQuestions | All of the expected questions. |
from InteractsWithConsole |
array | $expectedChoices | All of the expected choice questions. |
from InteractsWithConsole |
protected callable|null | $originalDeprecationHandler | The original deprecation handler. |
from InteractsWithDeprecationHandling |
protected ExceptionHandler|null | $originalExceptionHandler | The original exception handler. |
from InteractsWithExceptionHandling |
protected | $except | from InteractsWithExceptionHandling | |
protected | $originalHandler | from InteractsWithExceptionHandling | |
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 Throwable | $callbackException | The exception thrown while running an application destruction callback. |
|
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.
Mock a partial instance of an object in the container.
Instruct the container to forget a previously mocked / spied instance of an object.
Register an empty handler for Laravel Mix in the container.
Register an empty handler for Laravel Mix in the container.
Define additional headers to be sent with the request.
Add a header to be sent with the request.
Add an authorization token for the request.
Define a set of server variables to be sent with the requests.
Disable middleware for the test.
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 count of table entries.
Assert the given record has been deleted.
Assert the given record has been "soft deleted".
Assert the given record has not been "soft deleted".
Determine if the argument is a soft deletable model.
Cast a JSON string to a database compatible type.
Get the database connection.
Seed a given database connection.
Disable deprecation handling for the test.
Only handle the given exceptions via the exception handler.
Only handle validation exceptions via the exception handler.
Disable exception handling for the test.
Create a new TestView from the given view.
Render the contents of the given Blade template string.
Render the given view component.
Populate the shared view error bag with the given errors.
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.
Execute the application's pre-destruction callbacks.
Details
protected object
swap(string $abstract, object $instance)
Register an instance of an object in the container.
protected object
instance(string $abstract, object $instance)
Register an instance of an object in the container.
protected MockInterface
mock(string $abstract, Closure $mock = null)
Mock an instance of an object in the container.
protected MockInterface
partialMock(string $abstract, Closure $mock = null)
Mock a partial instance of an object in the container.
protected MockInterface
spy(string $abstract, Closure $mock = null)
Spy an instance of an object in the container.
protected $this
forgetMock(string $abstract)
Instruct the container to forget a previously mocked / spied instance of an object.
protected $this
withoutMix()
Register an empty handler for Laravel Mix in the container.
protected $this
withMix()
Register an empty handler for Laravel Mix in the container.
$this
withHeaders(array $headers)
Define additional headers to be sent with the request.
$this
withHeader(string $name, string $value)
Add a header to be sent with the request.
$this
withToken(string $token, string $type = 'Bearer')
Add an authorization token for the request.
$this
flushHeaders()
Flush all the configured headers.
$this
withServerVariables(array $server)
Define a set of server variables to be sent with the requests.
$this
withoutMiddleware(string|array|null $middleware = null)
Disable middleware for the test.
handle($request, $next)
No description
$this
actingAs(Authenticatable $user, string|null $guard = null)
Set the currently logged in user for the application.
$this
be(Authenticatable $user, string|null $guard = null)
Set the currently logged in user for the application.
$this
assertAuthenticated(string|null $guard = null)
Assert that the user is authenticated.
$this
assertGuest(string|null $guard = null)
Assert that the user is not authenticated.
protected bool
isAuthenticated(string|null $guard = null)
Return true if the user is authenticated, false otherwise.
$this
assertAuthenticatedAs(Authenticatable $user, string|null $guard = null)
Assert that the user is authenticated as the given user.
$this
assertCredentials(array $credentials, string|null $guard = null)
Assert that the given credentials are valid.
$this
assertInvalidCredentials(array $credentials, string|null $guard = null)
Assert that the given credentials are invalid.
protected bool
hasCredentials(array $credentials, string|null $guard = null)
Return true if the credentials are valid, false otherwise.
PendingCommand|int
artisan(string $command, array $parameters = [])
Call artisan command and return code.
protected $this
withoutMockingConsoleOutput()
Disable mocking the console output.
protected $this
assertDatabaseHas(Model|string $table, array $data, string|null $connection = null)
Assert that a given where condition exists in the database.
protected $this
assertDatabaseMissing(Model|string $table, array $data, string|null $connection = null)
Assert that a given where condition does not exist in the database.
protected $this
assertDatabaseCount(Model|string $table, int $count, string|null $connection = null)
Assert the count of table entries.
protected $this
assertDeleted(Model|string $table, array $data = [], string|null $connection = null)
Assert the given record has been deleted.
protected $this
assertSoftDeleted(Model|string $table, array $data = [], string|null $connection = null, string|null $deletedAtColumn = 'deleted_at')
Assert the given record has been "soft deleted".
protected $this
assertNotSoftDeleted(Model|string $table, array $data = [], string|null $connection = null, string|null $deletedAtColumn = 'deleted_at')
Assert the given record has not been "soft deleted".
protected $this
assertModelExists(Model $model)
Assert the given model exists in the database.
protected $this
assertModelMissing(Model $model)
Assert the given model does not exist in the database.
protected bool
isSoftDeletableModel(mixed $model)
Determine if the argument is a soft deletable model.
Expression
castAsJson(array|string $value)
Cast a JSON string to a database compatible type.
protected Connection
getConnection(string|null $connection = null)
Get the database connection.
protected string
getTable(Model|string $table)
Get the table name from the given model or string.
$this
seed(array|string $class = 'Database\\Seeders\\DatabaseSeeder')
Seed a given database connection.
protected $this
withDeprecationHandling()
Restore deprecation handling.
protected $this
withoutDeprecationHandling()
Disable deprecation handling for the test.
protected $this
withExceptionHandling()
Restore exception handling.
protected $this
handleExceptions(array $exceptions)
Only handle the given exceptions via the exception handler.
protected $this
handleValidationExceptions()
Only handle validation exceptions via the exception handler.
protected $this
withoutExceptionHandling(array $except = [])
Disable exception handling for the test.
void
__construct(ExceptionHandler $originalHandler, array $except = [])
Create a new class instance.
void
report(Throwable $e)
Report or log an exception.
bool
shouldReport(Throwable $e)
Determine if the exception should be reported.
void
renderForConsole(OutputInterface $output, Throwable $e)
Render an exception to the console.
$this
withSession(array $data)
Set the session to the given array.
$this
session(array $data)
Set the session to the given array.
protected $this
startSession()
Start the session for the application.
$this
flushSession()
Flush all of the current session data.
Wormhole
travel(int $value)
Begin travelling to another time.
mixed
travelTo(DateTimeInterface $date, callable|null $callback = null)
Travel to another time.
DateTimeInterface
travelBack()
Travel back to the current time.
protected TestView
view(string $view, array $data = [])
Create a new TestView from the given view.
protected TestView
blade(string $template, array $data = [])
Render the contents of the given Blade template string.
protected TestComponent
component(string $componentClass, array $data = [])
Render the given view component.
protected $this
withViewErrors(array $errors, string $key = 'default')
Populate the shared view error bag with the given errors.
$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.
$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.
protected $this
withoutEvents()
Mock the event dispatcher so all events are silenced and collected.
protected array
getFiredEvents(array $events)
Filter the given events against the fired events.
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.
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.
protected $this
withoutJobs()
Mock the job dispatcher so all jobs are silenced and collected.
protected array
getDispatchedJobs(array $jobs)
Filter the given jobs against the dispatched jobs.
protected array
getDispatched(array $classes, array $dispatched)
Filter the given classes against an array of dispatched classes.
protected bool
wasDispatched(string $needle, array $haystack)
Check if the given class exists in an array of dispatched classes.
protected $this
withoutNotifications()
Mock the notification dispatcher so all notifications are silenced.
protected $this
expectsNotification(mixed $notifiable, string $notification)
Specify a notification that is expected to be dispatched.
abstract HttpKernelInterface
createApplication()
Creates the application.
Needs to be implemented by subclasses.
protected void
setUp()
Setup the test environment.
protected void
refreshApplication()
Refresh the application instance.
protected array
setUpTraits()
Boot the testing helper traits.
protected 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.
protected void
beforeApplicationDestroyed(callable $callback)
Register a callback to be run before the application is destroyed.
protected void
callBeforeApplicationDestroyedCallbacks()
Execute the application's pre-destruction callbacks.