File: tests/TestCase.php
use Illuminate\Support\Facades\DB;
public function tearDown()
{
$sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'YOUR_DATABASE_NAME';";
DB::statement("SET FOREIGN_KEY_CHECKS = 0;");
$tables = DB::select($sql);
array_walk($tables, function($table){
if ($table->TABLE_NAME != 'migrations') {
DB::table($table->TABLE_NAME)->truncate();
}
});
DB::statement("SET FOREIGN_KEY_CHECKS = 1;");
parent::tearDown();
}
Why don't you try/catch to truncate function, so If there's an exception, you can catch it