【发布时间】:2019-01-21 11:22:34
【问题描述】:
我是 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]);
}
}
能帮我解决这个错误吗?提前致谢。
【问题讨论】:
-
你在 unit.suite.yml 中启用 Laravel5 模块了吗?
-
未启用,在您提出问题后,现在错误已解决。非常感谢。
标签: php laravel unit-testing laravel-5.2 codeception