I wanted to refresh my testing database once per class instead of per test using the setUpBeforeClass
method. As it is static, I can't call $this->artisan()
therefore I tried to use Artisan::call()
with facades.
The problem is that facades are not working here. I receive the error A facade root has not been set.
even though I uncommented $app->withFacades();
from bootstrap/app.php
.
How can I call an artisan command inside setUpBeforeClass
?
Here is my test class:
<?php
use Illuminate\Support\Facades\Artisan;
class ExampleTest extends TestCase
{
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
Artisan::call('migrate:fresh');
Artisan::call('db:seed --no-interaction');
}
public function testOne()
{
$this->assertTrue(true);
}
}