立面总是通过测试,不管我期望什么 return

facade always passing test never matter what return I expect

SkillAssessment::shouldReceive('addTwoNumbersAndAddName')
    ->with(3,5,'john')
    ->andReturn('thisstring is random and always passes anyway1341234123412343')->once();

一个非常基本的模型,预期 return 是:

8 john

所以我想写的是:

SkillAssessment::shouldReceive('addTwoNumbersAndAddName')
    ->with(3,5,'john')
    ->andReturn('8 john')->once();

它总是通过,不管我是否将 8 join 写入 return 或其他内容。

它失败了,但我一开始将 say:addTwoNumbersAndAddName 更改为其他内容,否则 ->with(4,10, 'john') 将失败

只有 ->andReturn() 不起作用

我正在使用 laravel 5.4 和命令 php artisan dusk

andReturn 方法 设置 测试替身 return.

它不会检查非测试替身是否会 return 该方法上的那个值。

所以您可能只是混淆了方法的使用。