Yii2 码处理数据找不到文件夹具



我正在尝试运行简单的测试,并通过fixture dataFile在数据库中插入两条记录。我得到的是:

[ReflectionException] Class C:xampphtdocscodeceptionfrontendtests/_datauser.php does not exist

文件显然在那里。我的UserTest.php看起来像这样:

<?php
class UserTest extends CodeceptionTestUnit
{
public function _fixtures()
{
return [
'class' => frontendtestsfixturesUserFixture::className(),
'dataFile' => codecept_data_dir() . 'user.php'
];
}
public function testValidation()
{
$user = new commonmodelsUser();
$user->setUsername(null);
$this->assertFalse($user->validate(['username']));
$user->setUsername('aaaaaaaaaaaaaaaaaaaaaaaaaa');
$this->assertFalse($user->validate(['username']));
$user->setUsername('toma');
$this->assertTrue($user->validate(['username']));
}
public function testIfUserExist()
{
$this->tester->seeRecord('user', ['name' => 'Toma']);
}
}

我在错误中看到了类似linux的正斜杠,但不知道如何更改它。不确定这是否是问题所在,因为我有一些图像的相同路径,当时一切都很好。是什么原因造成的?非常感谢。

您使用seeRecord()的方式不对。第一个参数需要按类名,包括名称空间,所以您应该这样使用它:

$this->tester->seeRecord(frontendmodelsUser::class, ['name' => 'Toma']);

最新更新