Test

Laravel Test

Database

Refresh Database

class ExampleTest extends TestCase
{
    use RefreshDatabase;
}

Seed Database

class ExampleTest extends TestCase
{
    protected $seed = true;
}

Truncate Table

class ExampleTest extends TestCase
{
    public function setUp(): void
    {
        parent::setUp();
        DB::table((new UserModel)->getTable())->truncate();
    }
}

URL

PHPUnit URL

https://laracasts.com/discuss/channels/laravel/phpunit-baseurl

class ExampleTest extends TestCase
{
    public function setUp(): void
    {
        parent::setUp();
        $app_url= "http://". request()->getHttpHost();;
        config(['app.url' => $app_url]);
        \URL::forceRootUrl($app_url);
    }
}

Reference


PHPUnit

Laravel Test PHPUnit

HTTP Tests

Laravel Test HTTP Tests

File Tests

Laravel Test File Tests