Database Testing
Introduction
Laravel provides a variety of helpful tools to make it easier to test your database driven applications. First, you may use the seeInDatabase
helper to assert that data exists in the database matching a given set of criteria. For example, if you would like to verify that there is a record in the users
table with the email
value of sally@example.com
, you can do the following:
1 2 3 4 5 6 7 8 | public function testDatabase() { // Make call to application... $this ->seeInDatabase( 'users' , [ 'email' => 'sally@example.com' ]); } |
Of course, the seeInDatabase
method and other helpers like it are for convenience. You are free to use any of PHPUnit's built-in assertion methods to supplement your tests.
Resetting The Database After Each Test
It is often useful to reset your database after each test so that data from a previous test does not interfere with subsequent tests.
Please login to continue.