【发布时间】:2021-02-05 14:32:20
【问题描述】:
我构建了一个 API(背面:Laravel 和正面:Angular),我想测试我的 API。 我是 Laravel 的初学者,当我想做一些集成测试时遇到了问题。确实,我尝试了这个小测试:
class userTest extends TestCase
{
public function testExample()
{
$response = $this->getJson('/api/listUsers');
$response->assertStatus(200);
}
}
我总是有这个错误:
Doctrine\DBAL\Schema\SchemaException: There is no column with name 'deleted_at' on table 'users'.
虽然我的用户表中还存在“deleted_at”,所以我不明白,我在互联网上搜索但在运行 phpunit 命令时没有人收到此错误。
class CreateUsersTable extends Migration
{
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('firstname');
$table->string('lastname');
$table->string('email')->unique();
$table->string('password');
$table->date('date_of_birth');
$table->rememberToken();
$table->timestamps();
$table->softDeletes();
});
}
public function down()
{
Schema::dropIfExists('users');
Schema::table('users', function (Blueprint $table) {
$table->dropSoftDeletes();
});
}
}
还有我的用户类:
class User extends Authenticatable implements JWTSubject
{
// 1. Dépendances
use SoftDeletes;
use Notifiable;
// 2. properties
protected $appends = ['fullname', 'age'];
protected $fillable = [
'firstname', 'lastname', 'email', 'password','date_of_birth'
];
protected $hidden = [
'password', 'remember_token', 'created_at', 'updated_at', 'deleted_at', 'pivot',
];
protected $table = 'users';
// 3. getters & setters
public function setPasswordAttribute($password)
{
$this->attributes['password'] = bcrypt($password);
}
public function getFullNameAttribute() {
return ucfirst($this->firstname) . ' ' . ucfirst($this->lastname);
}
public function getAgeAttribute()
{
return Carbon::parse($this->attributes['date_of_birth'])->age;
}
public function getJWTIdentifier()
{
return $this->getKey();
}
public function getJWTCustomClaims()
{
return [];
}
// 4. other methods
public function projects()
{
return $this->belongsToMany(Project::class);
}
}
我可以帮忙吗??
【问题讨论】:
-
请分享您的用户类别。
-
你使用软删除了吗?
-
是的,我正在使用软删除
-
您在迁移文件时是否收到此错误?
-
我分享了我的用户类@El_Vanja
标签: php laravel api testing integration-testing