Each time I run my tests with
php artisan test
after when I want to see the inserted data in my database, the table is totally empty.
Here is my test
class ExampleTest extends TestCase
{
use RefreshDatabase;
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$ad = new Ad();
$ad->name = 'test';
$ad->price = 100000;
$ad->save();
$this->assertTrue($ad->id > 0);
var_dump($ad->id);
}
}
The test verifies if the database has well generated an id, and the result is correct each time.
From my point of view, the trait RefreshDatabase refreshes the database BEFORE each tests not after so .. how in the world is this possible?
NB: I am sure that I am checking the correct database because if I remove use RefreshDatabase
I can see the records.
Precision:
If instead of RefreshDatabase
I use DatabaseTransactions
I can see the records after running tests. I can't get my head around it...
RefreshDatabase
to clear the DB so tests don't affect eachother. – Incipient