Jun 18, 2018
17
Level 13
Refresh database Trait remove all data from mysql database
i just start laravel php unit but when i use Refreshdatabase Trait inside Test class, all records from mysql database get removed, although i updated phpunitxml.php connection to
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="ENABLE_REGISTRATION" value="true"/>
<env name="MAIL_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
here is my test class
namespace Tests\Feature\Category;
use Tests\TestCase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\RefreshDatabase; use App\models\Permission\Permission; use App\Models\Auth\Role;
class CategoryTest extends TestCase { use RefreshDatabase;
/** @test */
public function it_can_see_all_categories()
{
$this->assertTrue(true);
}
Level 14
Try this:
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
config(['database.default' => 'sqlite']);
return $app;
}
And you could also just try commenting out DB_CONNECTION from your .env file (if you have one.)
1 like
Please or to participate in this conversation.