how to call Illuminate\Support\Facades\DB methods in tearDownAfterClass function?
I get error Call to undefined method Illuminate\Support\Facades\DB::select()
use Illuminate\Support\Facades\DB;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
use RefreshDatabase;
public static function tearDownAfterClass(): void
{
$databases = DB::select("SHOW DATABASES LIKE '". env('SCHEMA_PREFIX')."%'",[]);
...
}
}
Had this problem myself, the only solution was a wierd hack found at https://laracasts.com/discuss/channels/testing/seedingunseeding-the-database-once-per-test-class?page=1#reply=609036
adds (new self())->setUp in tearDownAfterClass :
public static function tearDownAfterClass(): void
{
(new self())->setUp();
DB:statement('stuff');//works now
}
and may be, it can be like this:
public static function tearDownAfterClass(): void
{
self::setUp();
DB:statement('stuff');//works now
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With