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 DeferredCallbackCollection|null $originalDeferredCallbacksCollection

The original deferred callbacks collection.

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
bool|null $expectsOutput

Indicates if the command is expected to output anything.

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.

from  InteractsWithTestCaseLifecycle
protected array $afterApplicationCreatedCallbacks

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

from  InteractsWithTestCaseLifecycle
protected array $beforeApplicationDestroyedCallbacks

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

from  InteractsWithTestCaseLifecycle
protected Throwable $callbackException

The exception thrown while running an application destruction callback.

from  InteractsWithTestCaseLifecycle
protected bool $setUpHasRun

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

from  InteractsWithTestCaseLifecycle

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.

MockInterface
mock(string $abstract, Closure|null $mock = null)

Mock an instance of an object in the container.

MockInterface
partialMock(string $abstract, Closure|null $mock = null)

Mock a partial instance of an object in the container.

MockInterface
spy(string $abstract, Closure|null $mock = null)

Spy an instance of an object in the container.

$this
forgetMock(string $abstract)

Instruct the container to forget a previously mocked / spied instance of an object.

$this
withoutVite()

Register an empty handler for Vite in the container.

__invoke($entrypoints, $buildDirectory = null)

No description

__call($method, $parameters)

No description

__toString()

No description

useIntegrityKey($key)

No description

useBuildDirectory($path)

No description

useHotFile($path)

No description

withEntryPoints($entryPoints)

No description

useScriptTagAttributes($attributes)

No description

useStyleTagAttributes($attributes)

No description

usePreloadTagAttributes($attributes)

No description

preloadedAssets()

No description

reactRefresh()

No description

content($asset, $buildDirectory = null)

No description

asset($asset, $buildDirectory = null)

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
withoutHeader(string $name)

Remove a header from the request.

$this
withoutHeaders(array $headers)

Remove headers from 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.

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.

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

Return true if the credentials are valid, false otherwise.

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

Call artisan command and return code.

$this
withoutMockingConsoleOutput()

Disable mocking the console output.

$this
assertDatabaseHas(Model|string $table, array $data = [], string|null $connection = null)

Assert that a given where condition exists in the database.

$this
assertDatabaseMissing(Model|string $table, array $data = [], string|null $connection = null)

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

$this
assertDatabaseCount(Model|string $table, int $count, string|null $connection = null)

Assert the count of table entries.

$this
assertDatabaseEmpty(Model|string $table, string|null $connection = null)

Assert that the given table has no entries.

$this
assertSoftDeleted(Model|string $table, array $data = [], string|null $connection = null, string|null $deletedAtColumn = 'deleted_at')

Assert the given record has been "soft deleted".

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

$this
assertModelExists(Model $model)

Assert the given model exists in the database.

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

bool
isSoftDeletableModel(mixed $model)

Determine if the argument is a soft deletable model.

castAsJson(array|object|string $value, string|null $connection = null)

Cast a JSON string to a database compatible type.

getConnection(string|null $connection = null, string|null $table = null)

Get the database connection.

string
getTable(Model|string $table)

Get the table name from the given model or string.

string|null
getTableConnection(Model|string $table)

Get the table connection specified in the given model.

string
getDeletedAtColumn(string $table, string $defaultColumnName = 'deleted_at')

Get the table column name used for soft deletes.

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.

$this
withDeprecationHandling()

Restore deprecation handling.

$this
withoutDeprecationHandling()

Disable deprecation handling for the test.

string
firstClosureParameterType(Closure $closure)

Get the class name of the first parameter of the given Closure.

array
firstClosureParameterTypes(Closure $closure)

Get the class names of the first parameter of the given Closure, including union types.

array
closureParameterTypes(Closure $closure)

Get the class names / types of the parameters of the given Closure.

$this
withExceptionHandling()

Restore exception handling.

$this
handleExceptions(array $exceptions)

Only handle the given exceptions via the exception handler.

$this
handleValidationExceptions()

Only handle validation exceptions via the exception handler.

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

Response
render(Request $request, Throwable $e)

Render an exception into an HTTP response.

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.

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

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.

travelBack()

Travel back to the current time.

void
setUpTheTestEnvironment()

Setup the test environment.

void
tearDownTheTestEnvironment()

Clean up the testing environment before the next test.

array
setUpTraits()

Boot the testing helper traits.

static void
tearDownAfterClassUsingTestCase()

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.

view(string $view, Arrayable|array $data = [])

Create a new TestView from the given view.

blade(string $template, Arrayable|array $data = [])

Render the contents of the given Blade template string.

component(string $componentClass, Arrayable|array $data = [])

Render the given view component.

$this
withViewErrors(array $errors, string $key = 'default')

Populate the shared view error bag with the given errors.

createApplication()

Creates the application.

void
setUp()

Setup the test environment.

void
refreshApplication()

Refresh the application instance.

void
tearDown()

Clean up the testing environment before the next test.

static void
tearDownAfterClass()

Clean up the testing environment before the next test case.

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

protected MockInterface mock(string $abstract, Closure|null $mock = null)

Mock an instance of an object in the container.

Parameters

string $abstract
Closure|null $mock

Return Value

MockInterface

protected MockInterface partialMock(string $abstract, Closure|null $mock = null)

Mock a partial instance of an object in the container.

Parameters

string $abstract
Closure|null $mock

Return Value

MockInterface

protected MockInterface spy(string $abstract, Closure|null $mock = null)

Spy an instance of an object in the container.

Parameters

string $abstract
Closure|null $mock

Return Value

MockInterface

protected $this forgetMock(string $abstract)

Instruct the container to forget a previously mocked / spied instance of an object.

Parameters

string $abstract

Return Value

$this

protected $this withoutVite()

Register an empty handler for Vite in the container.

Return Value

$this

__invoke($entrypoints, $buildDirectory = null)

No description

Parameters

$entrypoints
$buildDirectory

__call($method, $parameters)

No description

Parameters

$method
$parameters

__toString()

No description

useIntegrityKey($key)

No description

Parameters

$key

useBuildDirectory($path)

No description

Parameters

$path

useHotFile($path)

No description

Parameters

$path

withEntryPoints($entryPoints)

No description

Parameters

$entryPoints

useScriptTagAttributes($attributes)

No description

Parameters

$attributes

useStyleTagAttributes($attributes)

No description

Parameters

$attributes

usePreloadTagAttributes($attributes)

No description

Parameters

$attributes

preloadedAssets()

No description

reactRefresh()

No description

content($asset, $buildDirectory = null)

No description

Parameters

$asset
$buildDirectory

asset($asset, $buildDirectory = null)

No description

Parameters

$asset
$buildDirectory

$this withHeaders(array $headers)

Define additional headers to be sent with the request.

Parameters

array $headers

Return Value

$this

$this withHeader(string $name, string $value)

Add a header to be sent with the request.

Parameters

string $name
string $value

Return Value

$this

$this withoutHeader(string $name)

Remove a header from the request.

Parameters

string $name

Return Value

$this

$this withoutHeaders(array $headers)

Remove headers from the request.

Parameters

array $headers

Return Value

$this

$this withToken(string $token, string $type = 'Bearer')

Add an authorization token for the request.

Parameters

string $token
string $type

Return Value

$this

$this withBasicAuth(string $username, string $password)

Add a basic authentication header to the request with the given credentials.

Parameters

string $username
string $password

Return Value

$this

$this withoutToken()

Remove the authorization token from the request.

Return Value

$this

$this flushHeaders()

Flush all the configured headers.

Return Value

$this

$this withServerVariables(array $server)

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

Parameters

array $server

Return Value

$this

$this withoutMiddleware(string|array|null $middleware = null)

Disable middleware for the test.

Parameters

string|array|null $middleware

Return Value

$this

handle($request, $next)

No description

Parameters

$request
$next

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

Set the currently logged in user for the application.

Parameters

Authenticatable $user
string|null $guard

Return Value

$this

$this be(Authenticatable $user, string|null $guard = null)

Set the currently logged in user for the application.

Parameters

Authenticatable $user
string|null $guard

Return Value

$this

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

Assert that the user is authenticated.

Parameters

string|null $guard

Return Value

$this

$this assertGuest(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 assertAuthenticatedAs(Authenticatable $user, string|null $guard = null)

Assert that the user is authenticated as the given user.

Parameters

Authenticatable $user
string|null $guard

Return Value

$this

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

Assert that the given credentials are valid.

Parameters

array $credentials
string|null $guard

Return Value

$this

$this assertInvalidCredentials(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

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

Call artisan command and return code.

Parameters

string $command
array $parameters

Return Value

PendingCommand|int

protected $this withoutMockingConsoleOutput()

Disable mocking the console output.

Return Value

$this

protected $this assertDatabaseHas(Model|string $table, array $data = [], string|null $connection = null)

Assert that a given where condition exists in the database.

Parameters

Model|string $table
array $data
string|null $connection

Return Value

$this

protected $this assertDatabaseMissing(Model|string $table, array $data = [], string|null $connection = null)

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

Parameters

Model|string $table
array $data
string|null $connection

Return Value

$this

protected $this assertDatabaseCount(Model|string $table, int $count, string|null $connection = null)

Assert the count of table entries.

Parameters

Model|string $table
int $count
string|null $connection

Return Value

$this

protected $this assertDatabaseEmpty(Model|string $table, string|null $connection = null)

Assert that the given table has no entries.

Parameters

Model|string $table
string|null $connection

Return Value

$this

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".

Parameters

Model|string $table
array $data
string|null $connection
string|null $deletedAtColumn

Return Value

$this

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".

Parameters

Model|string $table
array $data
string|null $connection
string|null $deletedAtColumn

Return Value

$this

protected $this assertModelExists(Model $model)

Assert the given model exists in the database.

Parameters

Model $model

Return Value

$this

protected $this assertModelMissing(Model $model)

Assert the given model does not exist in the database.

Parameters

Model $model

Return Value

$this

$this expectsDatabaseQueryCount(int $expected, string|null $connection = null)

Specify the number of database queries that should occur throughout the test.

Parameters

int $expected
string|null $connection

Return Value

$this

protected bool isSoftDeletableModel(mixed $model)

Determine if the argument is a soft deletable model.

Parameters

mixed $model

Return Value

bool

Expression castAsJson(array|object|string $value, string|null $connection = null)

Cast a JSON string to a database compatible type.

Parameters

array|object|string $value
string|null $connection

Return Value

Expression

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

Get the database connection.

Parameters

string|null $connection
string|null $table

Return Value

Connection

protected string getTable(Model|string $table)

Get the table name from the given model or string.

Parameters

Model|string $table

Return Value

string

protected string|null getTableConnection(Model|string $table)

Get the table connection specified in the given model.

Parameters

Model|string $table

Return Value

string|null

protected string getDeletedAtColumn(string $table, string $defaultColumnName = 'deleted_at')

Get the table column name used for soft deletes.

Parameters

string $table
string $defaultColumnName

Return Value

string

protected Model|null newModelFor(Model|string $table)

Get the model entity from the given model or string.

Parameters

Model|string $table

Return Value

Model|null

$this seed(array|string $class = 'Database\\Seeders\\DatabaseSeeder')

Seed a given database connection.

Parameters

array|string $class

Return Value

$this

protected $this withDeprecationHandling()

Restore deprecation handling.

Return Value

$this

protected $this withoutDeprecationHandling()

Disable deprecation handling for the test.

Return Value

$this

protected string firstClosureParameterType(Closure $closure)

Get the class name of the first parameter of the given Closure.

Parameters

Closure $closure

Return Value

string

Exceptions

ReflectionException
RuntimeException

protected array firstClosureParameterTypes(Closure $closure)

Get the class names of the first parameter of the given Closure, including union types.

Parameters

Closure $closure

Return Value

array

Exceptions

ReflectionException
RuntimeException

protected array closureParameterTypes(Closure $closure)

Get the class names / types of the parameters of the given Closure.

Parameters

Closure $closure

Return Value

array

Exceptions

ReflectionException

protected $this withExceptionHandling()

Restore exception handling.

Return Value

$this

protected $this handleExceptions(array $exceptions)

Only handle the given exceptions via the exception handler.

Parameters

array $exceptions

Return Value

$this

protected $this handleValidationExceptions()

Only handle validation exceptions via the exception handler.

Return Value

$this

protected $this withoutExceptionHandling(array $except = [])

Disable exception handling for the test.

Parameters

array $except

Return Value

$this

void __construct(ExceptionHandler $originalHandler, array $except = [])

Create a new class instance.

Parameters

ExceptionHandler $originalHandler
array $except

Return Value

void

void report(Throwable $e)

Report or log an exception.

Parameters

Throwable $e

Return Value

void

Exceptions

Exception

bool shouldReport(Throwable $e)

Determine if the exception should be reported.

Parameters

Throwable $e

Return Value

bool

Response render(Request $request, Throwable $e)

Render an exception into an HTTP response.

Parameters

Request $request
Throwable $e

Return Value

Response

Exceptions

Throwable

void renderForConsole(OutputInterface $output, Throwable $e)

Render an exception to the console.

Parameters

OutputInterface $output
Throwable $e

Return Value

void

$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

mixed freezeTime(callable|null $callback = null)

Freeze time.

Parameters

callable|null $callback

Return Value

mixed

mixed freezeSecond(callable|null $callback = null)

Freeze time at the beginning of the current second.

Parameters

callable|null $callback

Return Value

mixed

Wormhole travel(int $value)

Begin travelling to another time.

Parameters

int $value

Return Value

Wormhole

mixed travelTo(DateTimeInterface|Closure|Carbon|string|bool|null $date, callable|null $callback = null)

Travel to another time.

Parameters

DateTimeInterface|Closure|Carbon|string|bool|null $date
callable|null $callback

Return Value

mixed

DateTimeInterface travelBack()

Travel back to the current time.

Return Value

DateTimeInterface

protected void setUpTheTestEnvironment()

internal  
 

Setup the test environment.

Return Value

void

protected void tearDownTheTestEnvironment()

internal  
 

Clean up the testing environment before the next test.

Return Value

void

protected array setUpTraits()

Boot the testing helper traits.

Return Value

array

static void tearDownAfterClassUsingTestCase()

internal  
 

Clean up the testing environment before the next test case.

Return Value

void

void afterApplicationCreated(callable $callback)

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

Parameters

callable $callback

Return Value

void

protected void beforeApplicationDestroyed(callable $callback)

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

Parameters

callable $callback

Return Value

void

protected void callBeforeApplicationDestroyedCallbacks()

Execute the application's pre-destruction callbacks.

Return Value

void

protected TestView view(string $view, Arrayable|array $data = [])

Create a new TestView from the given view.

Parameters

string $view
Arrayable|array $data

Return Value

TestView

protected TestView blade(string $template, Arrayable|array $data = [])

Render the contents of the given Blade template string.

Parameters

string $template
Arrayable|array $data

Return Value

TestView

protected TestComponent component(string $componentClass, Arrayable|array $data = [])

Render the given view component.

Parameters

string $componentClass
Arrayable|array $data

Return Value

TestComponent

protected $this withViewErrors(array $errors, string $key = 'default')

Populate the shared view error bag with the given errors.

Parameters

array $errors
string $key

Return Value

$this

Application createApplication()

Creates the application.

Return Value

Application

protected void setUp()

Setup the test environment.

Return Value

void

protected void refreshApplication()

Refresh the application instance.

Return Value

void

protected void tearDown()

Clean up the testing environment before the next test.

Return Value

void

Exceptions

InvalidCountException

static void tearDownAfterClass()

Clean up the testing environment before the next test case.

Return Value

void