laravel - 测试“工厂”未定义
问题描述
嗨,我正在尝试实施 test_user_can_login_with_correct_credentials 测试,但我无法弄清楚为什么会出现“工厂”未定义错误。
我在网上搜索过,人们似乎得到了这个,因为他们没有导入用户模型,但我有
这是代码
<?php
namespace Tests\Feature;
use Tests\TestCase;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Carbon\Carbon;
class LoginTest extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
public function test_user_can_view_a_login_form()
{
$response = $this->get('/login');
$response->assertSuccessful();
$response->assertViewIs('auth.login');
}
public function test_user_can_login_with_correct_credentials()
{
$user = factory(User::class)->create([ // Error with 'factory' on this line
'first_name' =>('John'),
'last_name' => ('Smith'),
'email' => ('john@example.com'),
'date_of_birth' => ('16/02/2001'),
'password' => Hash::make('test'),
'join_date' => Carbon::now()
]);
$response = $this->from('/login')->post('/login', [
'email' => $user->email,
'password' => 'test',
]);
$response->assertRedirect('/login');
$response->assertSessionHasErrors('email');
$this->assertTrue(session()->hasOldInput('email'));
$this->assertFalse(session()->hasOldInput('password'));
$this->assertGuest();
}
}
确切的错误是'未定义的函数'Tests\Feature\factory'.intelephense(1010)'
任何帮助将不胜感激我不确定如何解决这个问题
解决方案
推荐阅读
- c# - 绘制碰撞器边界(Unity)
- swift - 我想让应用程序在朋友之间分摊账单
- python - 如何对字典中的字典列表进行排序并在python中覆盖它
- android - 在 Flutter Android 中读取托管应用配置
- r - 根据 R 中发生日期的延续分配特征编号
- reactjs - React 功能组件 html5 视频播放器捕获事件
- phpstorm - 使用自我类型提示的 PhpStorm 错误检查错误
- html - 让文本出现在图像之后而不是它旁边(在 CSS 或 HTML 中)
- c# - 无法使用 EF Core 从 MS SQL Server 检索数据
- mongodb - MongoDB - 如何在聚合的 $match 中比较不同集合的字段?