【问题标题】:Codeception Unit testing [RuntimeException] Call to undefined method UnitTester::haveRecordCodeception 单元测试 [RuntimeException] 调用未定义的方法 UnitTester::haveRecord
【发布时间】: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


【解决方案1】:

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

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

actor: UnitTester
modules:
 enabled:
    - Asserts
    - Laravel5:
        part: ORM
    - \Helper\Unit

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多