【发布时间】:2014-08-19 16:59:18
【问题描述】:
我有一个使用 Str::random() 的课程,我想对其进行测试。
但是当我在测试中使用Str::shouldReceive('random') 时,我得到一个 BadMethodCallException 说方法 shouldReceive 不存在。
我也尝试直接模拟该类并将其绑定到 IOC,但它继续执行原始类,生成一个随机字符串而不是我在模拟上设置的返回值。
$stringHelper = Mockery::mock('Illuminate\Support\Str');
$this->app->instance('Illuminate\Support\Str', $stringHelper);
//$this->app->instance('Str', $stringHelper);
$stringHelper->shouldReceive('random')->once()->andReturn('some password');
//Str::shouldReceive('random')->once()->andReturn('some password');
【问题讨论】:
标签: unit-testing laravel facade mockery