使用Laravel (8.44.0) assetion assertModelExists()对数据库进行测试,如果出现错误,则失败。
Error : Call to undefined method Tests\Feature\CommuneTest::assertModelExists()测试类如下所示
<?php
namespace Tests\Feature;
use App\Models\Commune;
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class CommuneTest extends TestCase
{
use RefreshDatabase, InteractsWithDatabase;
/**
* Test can save a commune model on DB
*
* @return void
* @test
*/
public function canStoreDb()
{
$commune = Commune::factory()->create();
$this->assertModelExists($commune);
}
}你觉得少了什么?
发布于 2022-01-06 20:10:28
2021年9月添加了assertModelExists方法:
https://github.com/laravel/framework/pull/38766
版本8.44.0于2021年5月发布:
https://github.com/laravel/framework/releases/tag/v8.44.0
所以,只要将Laravel更新到最新的8.x版本,就可以了。
https://stackoverflow.com/questions/70612908
复制相似问题