create([ 'name' => '测试数据1', 'description' => '这是一个测试数据' ]); // 验证数据存在 $this->assertDatabaseHas('tests', [ 'id' => $test->id, 'name' => '测试数据1', 'description' => '这是一个测试数据' ]); // 软删除数据 $test->delete(); // 验证数据在正常查询中不可见 $this->assertDatabaseMissing('tests', [ 'id' => $test->id, 'name' => '测试数据1', 'description' => '这是一个测试数据' ]); // 验证数据在软删除表中可见 $this->assertSoftDeleted('tests', [ 'id' => $test->id, 'name' => '测试数据1', 'description' => '这是一个测试数据' ]); // 恢复数据 $test->restore(); // 验证数据恢复后可见 $this->assertDatabaseHas('tests', [ 'id' => $test->id, 'name' => '测试数据1', 'description' => '这是一个测试数据' ]); } /** * 测试强制删除功能 */ public function test_force_delete(): void { // 创建测试数据 $test = Test::factory()->create([ 'name' => '测试数据2', 'description' => '这是另一个测试数据' ]); // 软删除数据 $test->delete(); // 强制删除数据 $test->forceDelete(); // 验证数据完全删除 $this->assertDatabaseMissing('tests', [ 'id' => $test->id, 'name' => '测试数据2', 'description' => '这是另一个测试数据' ]); } }