Codeception单元测试[RuntimeException]调用未定义的方法UnitTester :: haveRecord

时间:2019-01-21 11:22:35

标签: php laravel unit-testing laravel-5.2 codeception

我是Codeception的新手,试图在我的Laravel框架中运行示例单元测试,但收到以下错误:

[RuntimeException] Call to undefined method UnitTester::haveRecord

以下是我尝试使用Codeception运行的代码:

 <?php namespace Article;
 use App\Article;
 use Faker\Factory as Faker;
 use Carbon\Carbon;
 class SaveTest extends \Codeception\Test\Unit
{
/**
 * @var \UnitTester
 */
protected $tester;

protected function _before()
{
}

protected function _after()
{
}

// tests
public function testSomeFeature()
{
    $faker= Faker::create('App/Article');

        $title = $faker->sentence;
        $content = implode($faker->paragraphs(5));
        $created_at = Carbon::now();
        $updated_at = Carbon::now();


        $this->tester->haveRecord( 'Article',   ['title' => $title, 'content' => $content,'created_at' => $created_at,'updated_at' => $updated_at]);


         $this->tester->seeRecord('articles',['title' => $title,'content' => $content,'created_at' => $created_at,'updated_at' => $updated_at]);




}
}

请帮我解决这个错误?预先感谢。

1 个答案:

答案 0 :(得分:0)

我在unit.suite.yml中启用了Laravel5模块后,问题解决了

带有Laravel5模块的unit.suite.yml文件格式:

<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<a routerLink="/" class="navbar-brand" href="#">Bootsrap 4</a>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="about">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact">Contact us</a>
</li>
</ul>
</nav>