du94414 2018-05-19 12:48
浏览 60
已采纳

too long

I'm keep getting the following error when using laravel's assertDatabaseHas() method in my tests.

Error: Call to undefined method Illuminate\Http\Response::assertDatabaseHas()

this is my code fragment using assertDatabaseHas() :

$response = $this->withSession(['user_id' => $this->user_id])
        ->json('post',
                route('some_route'),
                $request //an array 
            );

        $request['myuser_id'] = $this->user_id;

        $response->assertStatus($expected['code'])
            ->assertDatabaseHas('profiles',$request);

I also tried to use $this->assertDatabaseHas(), but a new error appeared:

TypeError: Argument 2 passed to PHPUnit\Framework\Assert::assertThat() must be an instance of PHPUnit\Framework\Constraint\Constraint, instance of Illuminate\Foundation\Testing\Constraints\HasInDatabase given, called in /project_path/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php on line 22

I searched for a while for the problem's solution and found this one : solution , but downgrading phpunit version to 5.* didn't work for me.

I'm using laravel 5.4 and phpunit 6.5.5 .

any idea guys?

  • 写回答

1条回答 默认 最新

  • duanliaoyu8419 2018-05-21 08:36
    关注

    I upgraded my laravel version from 5.4.37 to 5.5.40 and problem solved. assertDatabaseHas() works fine now.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog