首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >落地试验Laravel assertModelExists

落地试验Laravel assertModelExists
EN

Stack Overflow用户
提问于 2022-01-06 19:53:03
回答 1查看 227关注 0票数 0

使用Laravel (8.44.0) assetion assertModelExists()对数据库进行测试,如果出现错误,则失败。

代码语言:javascript
复制
Error : Call to undefined method Tests\Feature\CommuneTest::assertModelExists()

测试类如下所示

代码语言:javascript
复制
<?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);
    }
}

你觉得少了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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版本,就可以了。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70612908

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档