CI Gitlab 上单元测试的一些问题

Some issue with Unit Testing on CI Gitlab

晚安,

我在 运行 通过 CI 调整我的代码时遇到问题。当我 运行 我的代码在本地时,测试没问题。

所以我有一个榜样(没有双关语意)

在我的测试中,我将角色分配给新创建的测试用户。

 // Assigning Role
        $role = Role::where('name','administrator')->first();
        $user->assignRole($role);

分配角色是通过我的用户模型添加的

/**
     * Assigns Role to the User
     *
     * @param Role $role
     */
    public function assignRole(Role $role)
    {
        $this->roles()->save($role);
    }

当我 运行 在本地进行测试时,它按预期工作。

   PASS  Tests\Feature\UserTest
  ✓ user login
  ✓ users list allowed
  ✓ users list not allowed
  ✓ user creation
  ✓ user delete

  Tests:  6 passed
  Time:   7.05s

但是当我 运行 在我的 CI 环境中使用它时。我收到以下错误消息:

 ✓ basic test
   FAIL  Tests\Feature\UserTest
  ✓ user login
  ✓ users list allowed
  ✓ users list not allowed
  ⨯ user creation
  ✓ user delete
  ---
  • Tests\Feature\UserTest > user creation
   TypeError 
  Argument 1 passed to App\Models\User::assignRole() must be an instance of App\Models\Role, null given, called in /builds/marcel43/backendapi/tests/Feature/UserTest.php on line 86
  at app/Models/User.php:73
     69▕      * Assigns Role to the User
     70▕      *
     71▕      * @param Role $role
     72▕      */
  ➜  73▕     public function assignRole(Role $role)
     74▕     {
     75▕         $this->roles()->save($role);
     76▕     }
     77▕
  1   tests/Feature/UserTest.php:86
      App\Models\User::assignRole()
  Tests:  1 failed, 5 passed
  Time:   0.97s

我在这里错过了什么?

我对我的数据库做种很生气,我创建了做种器但没有将它添加到数据库中。这就是它找不到角色的原因。