TestCase
abstract class TestCase extends TestCase (View source)
Traits
InteractsWithContainer |
MakesHttpRequests |
InteractsWithAuthentication |
InteractsWithConsole |
InteractsWithDatabase |
InteractsWithExceptionHandling |
InteractsWithSession |
MocksApplicationServices |
Properties
protected array | $defaultHeaders | Additional headers 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 |
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 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 |
$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 | 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 $middleware = null) Disable middleware for the test. | from MakesHttpRequests |
handle($request, $next) No description | from MakesHttpRequests | |
$this | actingAs(Authenticatable $user, string|null $driver = null) Set the currently logged in user for the application. | from InteractsWithAuthentication |
$this | be(Authenticatable $user, string|null $driver = 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(string $table, array $data, string $connection = null) Assert that a given where condition exists in the database. | from InteractsWithDatabase |
$this | assertDatabaseMissing(string $table, array $data, string $connection = null) Assert that a given where condition does not exist in the database. | from InteractsWithDatabase |
$this | assertSoftDeleted(string $table, array $data, string $connection = null) Assert the given record has been deleted. | from InteractsWithDatabase |
Connection | getConnection(string|null $connection = null) Get the database connection. | from InteractsWithDatabase |
$this | seed(string $class = 'DatabaseSeeder') Seed a given database connection. | from InteractsWithDatabase |
$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(Exception $e) Report the given exception. | from InteractsWithExceptionHandling |
mixed | render(Request $request, Exception $e) Render the given exception. | from InteractsWithExceptionHandling |
void | renderForConsole(OutputInterface $output, Exception $e) Render the exception for 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 |
$this | expectsEvents(array|string $events) Specify a list of events that should be fired for the given operation. | from MocksApplicationServices |
$this | doesntExpectEvents(array|string $events) Specify a list of events that should not be fired for the given operation. | from MocksApplicationServices |
$this | withoutEvents() Mock the event dispatcher so all events are silenced and collected. | from MocksApplicationServices |
array | getFiredEvents(array $events) Filter the given events against the fired events. | from MocksApplicationServices |
$this | expectsJobs(array|string $jobs) Specify a list of jobs that should be dispatched for the given operation. | from MocksApplicationServices |
$this | doesntExpectJobs(array|string $jobs) Specify a list of jobs that should not be dispatched for the given operation. | from MocksApplicationServices |
$this | withoutJobs() Mock the job dispatcher so all jobs are silenced and collected. | from MocksApplicationServices |
array | getDispatchedJobs(array $jobs) Filter the given jobs against the dispatched jobs. | from MocksApplicationServices |
array | getDispatched(array $classes, array $dispatched) Filter the given classes against an array of dispatched classes. | from MocksApplicationServices |
bool | wasDispatched(string $needle, array $haystack) Check if the given class exists in an array of dispatched classes. | from MocksApplicationServices |
$this | withoutNotifications() Mock the notification dispatcher so all notifications are silenced. | from MocksApplicationServices |
$this | expectsNotification(mixed $notifiable, string $notification) Specify a notification that is expected to be dispatched. | from MocksApplicationServices |
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. |
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.
$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 $middleware = null)
Disable middleware for the test.
handle($request, $next)
$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.
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(string $table, array $data, string $connection = null)
Assert that a given where condition exists in the database.
protected $this assertDatabaseMissing(string $table, array $data, string $connection = null)
Assert that a given where condition does not exist in the database.
protected $this assertSoftDeleted(string $table, array $data, string $connection = null)
Assert the given record has been deleted.
protected Connection getConnection(string|null $connection = null)
Get the database connection.
$this seed(string $class = 'DatabaseSeeder')
Seed a given database connection.
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(Exception $e)
Report the given exception.
void renderForConsole(OutputInterface $output, Exception $e)
Render the exception for 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.
$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.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.7/Illuminate/Foundation/Testing/TestCase.html