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

Indicates if the console output should be mocked.

from  InteractsWithConsole
array $expectedOutput

All of the expected output lines.

from  InteractsWithConsole
array $expectedQuestions

All of the expected questions.

from  InteractsWithConsole
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

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 $mock = null)

Mock an instance of an object in the container.

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

Mock a partial instance of an object in the container.

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

Spy an instance of an object in the container.

$this
withoutMix()

Register an empty handler for Laravel Mix in the container.

$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
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 $driver = null)

Set the currently logged in user for the application.

$this
be(Authenticatable $user, string|null $driver = 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(string $table, array $data, string|null $connection = null)

Assert that a given where condition exists in the database.

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

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

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

Assert the given record has been deleted.

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

Assert the given record has been "soft deleted".

bool
isSoftDeletableModel(mixed $model)

Determine if the argument is a soft deletable model.

getConnection(string|null $connection = null)

Get the database connection.

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

Seed a given database connection.

$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(Exception $e)

Report or log an exception.

bool
shouldReport(Exception $e)

Determine if the exception should be reported.

Response
render(Request $request, Exception $e)

Render an exception into an HTTP response.

void
renderForConsole(OutputInterface $output, Exception $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.

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

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.

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 $mock = null)

Mock an instance of an object in the container.

Parameters

string $abstract
Closure $mock

Return Value

MockInterface

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

Mock a partial instance of an object in the container.

Parameters

string $abstract
Closure $mock

Return Value

MockInterface

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

Spy an instance of an object in the container.

Parameters

string $abstract
Closure $mock

Return Value

MockInterface

protected $this withoutMix()

Register an empty handler for Laravel Mix in the container.

Return Value

$this

protected $this withMix()

Register an empty handler for Laravel Mix in the container.

Return Value

$this

$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 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 $driver = null)

Set the currently logged in user for the application.

Parameters

Authenticatable $user
string|null $driver

Return Value

$this

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

Set the currently logged in user for the application.

Parameters

Authenticatable $user
string|null $driver

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

Assert that a given where condition exists in the database.

Parameters

string $table
array $data
string|null $connection

Return Value

$this

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

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

Parameters

string $table
array $data
string|null $connection

Return Value

$this

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

Assert the given record has been deleted.

Parameters

Model|string $table
array $data
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 bool isSoftDeletableModel(mixed $model)

Determine if the argument is a soft deletable model.

Parameters

mixed $model

Return Value

bool

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

Get the database connection.

Parameters

string|null $connection

Return Value

Connection

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

Seed a given database connection.

Parameters

array|string $class

Return Value

$this

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(Exception $e)

Report or log an exception.

Parameters

Exception $e

Return Value

void

Exceptions

Exception

bool shouldReport(Exception $e)

Determine if the exception should be reported.

Parameters

Exception $e

Return Value

bool

Response render(Request $request, Exception $e)

Render an exception into an HTTP response.

Parameters

Request $request
Exception $e

Return Value

Response

Exceptions

Exception

void renderForConsole(OutputInterface $output, Exception $e)

Render an exception to the console.

Parameters

OutputInterface $output
Exception $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

$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

abstract HttpKernelInterface createApplication()

Creates the application.

Needs to be implemented by subclasses.

Return Value

HttpKernelInterface

protected void setUp()

Setup the test environment.

Return Value

void

protected void refreshApplication()

Refresh the application instance.

Return Value

void

protected array setUpTraits()

Boot the testing helper traits.

Return Value

array

protected void tearDown()

Clean up the testing environment before the next test.

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