On this page
TestCase
abstract class TestCase extends TestCase (View source)
Traits
Properties
protected Vite|null | $originalVite | The original Vite handler. |
from InteractsWithContainer |
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 |
static TestResponse|null | $latestResponse | The latest test response (if any). |
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 | $expectedOutputSubstrings | All of the expected text to be present in the output. |
from InteractsWithConsole |
array | $unexpectedOutput | All of the output lines that aren't expected to be displayed. |
from InteractsWithConsole |
array | $unexpectedOutputSubstrings | All of the text that is not expected to be present in the output. |
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 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
object | swap(string $abstract, object $instance) Register an instance of an object in the container. |
from InteractsWithContainer |
object | instance(string $abstract, object $instance) Register an instance of an object in the container. |
from InteractsWithContainer |
MockInterface | mock(string $abstract, Closure $mock = null) Mock an instance of an object in the container. |
from InteractsWithContainer |
MockInterface | partialMock(string $abstract, Closure $mock = null) Mock a partial instance of an object in the container. |
from InteractsWithContainer |
MockInterface | spy(string $abstract, Closure $mock = null) Spy an instance of an object in the container. |
from InteractsWithContainer |
$this | forgetMock(string $abstract) Instruct the container to forget a previously mocked / spied instance of an object. |
from InteractsWithContainer |
$this | withoutVite() Register an empty handler for Vite in the container. |
from InteractsWithContainer |
__invoke() No description |
from InteractsWithContainer | |
__call($name, $arguments) No description |
from InteractsWithContainer | |
__toString() No description |
from InteractsWithContainer | |
useIntegrityKey() No description |
from InteractsWithContainer | |
useBuildDirectory() No description |
from InteractsWithContainer | |
useHotFile() No description |
from InteractsWithContainer | |
withEntryPoints() No description |
from InteractsWithContainer | |
useScriptTagAttributes() No description |
from InteractsWithContainer | |
useStyleTagAttributes() No description |
from InteractsWithContainer | |
preloadedAssets() No description |
from InteractsWithContainer | |
$this | withHeaders(array $headers) Define additional headers to be sent with the request. |
from MakesHttpRequests |
$this | withHeader(string $name, string $value) Add a header to be sent with the request. |
from MakesHttpRequests |
$this | withToken(string $token, string $type = 'Bearer') Add an authorization token for the request. |
from MakesHttpRequests |
$this | withBasicAuth(string $username, string $password) Add a basic authentication header to the request with the given credentials. |
from MakesHttpRequests |
$this | withoutToken() Remove the authorization token from the request. |
from MakesHttpRequests |
$this | flushHeaders() Flush all the configured headers. |
from MakesHttpRequests |
$this | withServerVariables(array $server) Define a set of server variables to be sent with the requests. |
from MakesHttpRequests |
$this | withoutMiddleware(string|array|null $middleware = null) Disable middleware for the test. |
from MakesHttpRequests |
handle($request, $next) No description |
from MakesHttpRequests | |
$this | actingAs(Authenticatable $user, string|null $guard = null) Set the currently logged in user for the application. |
from InteractsWithAuthentication |
$this | be(Authenticatable $user, string|null $guard = null) Set the currently logged in user for the application. |
from InteractsWithAuthentication |
$this | assertAuthenticated(string|null $guard = null) Assert that the user is authenticated. |
from InteractsWithAuthentication |
$this | assertGuest(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 | assertAuthenticatedAs(Authenticatable $user, string|null $guard = null) Assert that the user is authenticated as the given user. |
from InteractsWithAuthentication |
$this | assertCredentials(array $credentials, string|null $guard = null) Assert that the given credentials are valid. |
from InteractsWithAuthentication |
$this | assertInvalidCredentials(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 if the credentials are valid, false otherwise. |
from InteractsWithAuthentication |
PendingCommand|int | artisan(string $command, array $parameters = []) Call artisan command and return code. |
from InteractsWithConsole |
$this | withoutMockingConsoleOutput() Disable mocking the console output. |
from InteractsWithConsole |
$this | assertDatabaseHas(Model|string $table, array $data, string|null $connection = null) Assert that a given where condition exists in the database. |
from InteractsWithDatabase |
$this | assertDatabaseMissing(Model|string $table, array $data, string|null $connection = null) Assert that a given where condition does not exist in the database. |
from InteractsWithDatabase |
$this | assertDatabaseCount(Model|string $table, int $count, string|null $connection = null) Assert the count of table entries. |
from InteractsWithDatabase |
$this | assertDatabaseEmpty(Model|string $table, string|null $connection = null) Assert that the given table has no entries. |
from InteractsWithDatabase |
$this | assertSoftDeleted(Model|string $table, array $data = [], string|null $connection = null, string|null $deletedAtColumn = 'deleted_at') Assert the given record has been "soft deleted". |
from InteractsWithDatabase |
$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". |
from InteractsWithDatabase |
$this | assertModelExists(Model $model) Assert the given model exists in the database. |
from InteractsWithDatabase |
$this | assertModelMissing(Model $model) Assert the given model does not exist in the database. |
from InteractsWithDatabase |
$this | expectsDatabaseQueryCount(int $expected, string|null $connection = null) Specify the number of database queries that should occur throughout the test. |
from InteractsWithDatabase |
bool | isSoftDeletableModel(mixed $model) Determine if the argument is a soft deletable model. |
from InteractsWithDatabase |
Expression | castAsJson(array|object|string $value) Cast a JSON string to a database compatible type. |
from InteractsWithDatabase |
Connection | getConnection(string|null $connection = null, string|null $table = null) Get the database connection. |
from InteractsWithDatabase |
string | getTable(Model|string $table) Get the table name from the given model or string. |
from InteractsWithDatabase |
string|null | getTableConnection(Model|string $table) Get the table connection specified in the given model. |
from InteractsWithDatabase |
Model|null | newModelFor(Model|string $table) Get the model entity from the given model or string. |
from InteractsWithDatabase |
$this | seed(array|string $class = 'Database\\Seeders\\DatabaseSeeder') Seed a given database connection. |
from InteractsWithDatabase |
$this | withDeprecationHandling() Restore deprecation handling. |
from InteractsWithDeprecationHandling |
$this | withoutDeprecationHandling() Disable deprecation handling for the test. |
from InteractsWithDeprecationHandling |
$this | withExceptionHandling() Restore exception handling. |
from InteractsWithExceptionHandling |
$this | handleExceptions(array $exceptions) Only handle the given exceptions via the exception handler. |
from InteractsWithExceptionHandling |
$this | handleValidationExceptions() Only handle validation exceptions via the exception handler. |
from InteractsWithExceptionHandling |
$this | withoutExceptionHandling(array $except = []) Disable exception handling for the test. |
from InteractsWithExceptionHandling |
void | __construct(ExceptionHandler $originalHandler, array $except = []) Create a new class instance. |
from InteractsWithExceptionHandling |
void | report(Throwable $e) Report or log an exception. |
from InteractsWithExceptionHandling |
bool | shouldReport(Throwable $e) Determine if the exception should be reported. |
from InteractsWithExceptionHandling |
Response | render(Request $request, Throwable $e) Render an exception into an HTTP response. |
from InteractsWithExceptionHandling |
void | renderForConsole(OutputInterface $output, Throwable $e) Render an exception to the console. |
from InteractsWithExceptionHandling |
$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 |
mixed | freezeTime(callable|null $callback = null) Freeze time. |
from InteractsWithTime |
mixed | freezeSecond(callable|null $callback = null) Freeze time at the beginning of the current second. |
from InteractsWithTime |
Wormhole | travel(int $value) Begin travelling to another time. |
from InteractsWithTime |
mixed | travelTo(DateTimeInterface|Closure|Carbon|string|bool|null $date, callable|null $callback = null) Travel to another time. |
from InteractsWithTime |
DateTimeInterface | travelBack() Travel back to the current time. |
from InteractsWithTime |
TestView | view(string $view, Arrayable|array $data = []) Create a new TestView from the given view. |
from InteractsWithViews |
TestView | blade(string $template, Arrayable|array $data = []) Render the contents of the given Blade template string. |
from InteractsWithViews |
TestComponent | component(string $componentClass, Arrayable|array $data = []) Render the given view component. |
from InteractsWithViews |
$this | withViewErrors(array $errors, string $key = 'default') Populate the shared view error bag with the given errors. |
from InteractsWithViews |
HttpKernelInterface | createApplication() Creates the application. |
|
void | setUp() Setup the test environment. |
|
void | refreshApplication() Refresh the application instance. |
|
array | setUpTraits() Boot the testing helper traits. |
|
mixed | runTest() {@inheritdoc} |
|
void | tearDown() Clean up the testing environment before the next test. |
|
static void | tearDownAfterClass() Clean up the testing environment before the next test case. |
|
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. |
|
void | callBeforeApplicationDestroyedCallbacks() 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 withoutVite()
Register an empty handler for Vite in the container.
__invoke()
No description
__call($name, $arguments)
No description
__toString()
No description
useIntegrityKey()
No description
useBuildDirectory()
No description
useHotFile()
No description
withEntryPoints()
No description
useScriptTagAttributes()
No description
useStyleTagAttributes()
No description
preloadedAssets()
No description
$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 withBasicAuth(string $username, string $password)
Add a basic authentication header to the request with the given credentials.
$this withoutToken()
Remove the authorization token from 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 assertDatabaseEmpty(Model|string $table, string|null $connection = null)
Assert that the given table has no entries.
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.
$this expectsDatabaseQueryCount(int $expected, string|null $connection = null)
Specify the number of database queries that should occur throughout the test.
protected bool isSoftDeletableModel(mixed $model)
Determine if the argument is a soft deletable model.
Expression castAsJson(array|object|string $value)
Cast a JSON string to a database compatible type.
protected Connection getConnection(string|null $connection = null, string|null $table = null)
Get the database connection.
protected string getTable(Model|string $table)
Get the table name from the given model or string.
protected string|null getTableConnection(Model|string $table)
Get the table connection specified in the given model.
protected Model|null newModelFor(Model|string $table)
Get the model entity 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.
mixed freezeTime(callable|null $callback = null)
Freeze time.
mixed freezeSecond(callable|null $callback = null)
Freeze time at the beginning of the current second.
Wormhole travel(int $value)
Begin travelling to another time.
mixed travelTo(DateTimeInterface|Closure|Carbon|string|bool|null $date, callable|null $callback = null)
Travel to another time.
DateTimeInterface travelBack()
Travel back to the current time.
protected TestView view(string $view, Arrayable|array $data = [])
Create a new TestView from the given view.
protected TestView blade(string $template, Arrayable|array $data = [])
Render the contents of the given Blade template string.
protected TestComponent component(string $componentClass, Arrayable|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.
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 mixed runTest()
{@inheritdoc}
protected void tearDown()
Clean up the testing environment before the next test.
static void tearDownAfterClass()
Clean up the testing environment before the next test case.
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.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/10.x/Illuminate/Foundation/Testing/TestCase.html