我正在尝试为我的db浏览器编写集成测试,但它似乎没有返回该播种器的实例。所以它无法执行
当我调试它时,$ adminUserSeeder显示以下内容
这是我的测试
namespace Tests\Unit\user;
use AdminUserSeeder;
use App\Test;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use PHPUnit\Framework\TestCase;
class AdminSeederTest extends TestCase
{
use DatabaseTransactions;
public function setUp()
{
parent::setUp();
}
public function testRun()
{
$adminUserSeeder = new AdminUserSeeder();
$adminUserSeeder->run();
$this->assertDatabaseHas('users', ['name' => 'admin']);
}
}
这是我的播种机课程
使用Illuminate \ Database \ Seeder;
class AdminUserSeeder extends Seeder
{
public function run()
{
$user = (new App\User)->where('name','admin')->first();
if($user)
{
$user->delete();
}
factory(App\User::class,'admin')->create();
}
}
添加了堆栈跟踪
/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1138
/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1104
/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:936
/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:880
/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:843
/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1477
/database/seeds/AdminUserSeeder.php:10
/tests/Unit/AdminSeederTest.php:21