【发布时间】:2021-11-26 18:49:40
【问题描述】:
我的测试:
class FloorStackTest extends TestCase
{
use RefreshDatabase, WithFaker, DatabaseMigrations;
protected $endPoint = '/endpoint';
public function test_unit_type_note_added_successfully()
{
$this->signIn();
$this->withoutExceptionHandling();
$unitType = UnitType::factory()->create();
$note = $this->faker()->sentence(3);
$resp = $this->ajaxPost($this->admin_route.$this->endPoint."/".$unitType->property_version_id."/save-ut-note",[
'notes' => [
[
"ut_note_id" => "utn_".$unitType->id,
"note" => $note
]
]
])->assertStatus(Response::HTTP_OK);
$results = [
'notes' => $note
];
//i could print upto here
dd('hit');
$this->assertDatabaseHas(UnitType::class,$results);
//but could not print here
dd('hit');
}
}
我使用sqlite 进行测试,我使用的是 laravel 8(之前是从 laravel 5 更新的,以防万一确认)
我上面的代码,你可以看到我可以print hit的点。
我正在使用.env.testing
DB_CONNECTION=sqlite
DB_DATABASE="database/test.sqlite"
DB_FOREIGN_KEYS=false
我已经在使用:use RefreshDatabase,但它仍然显示错误。完整的错误是:
Tests\Feature\FloorStackTest::test_unit_type_note_added_successfully
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such table: App\Models\UnitType (SQL: select count(*) as aggregate from "App\Models\UnitType" where ("notes" = Eveniet incidunt consequuntur dolore est.))
我的模特UnitType 有这个
use SoftDeletes, HasFactory;
protected $table = 'unit_types';
protected $guarded = ['id'];
protected $dates = ['created_at','updated_at','deleted_at'];
【问题讨论】: