我有一个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');
Run Code Online (Sandbox Code Playgroud)