codecamp

模拟 Facades

当测试的时候,你或许常会想要模拟调用 Laravel 静态 facade。举个例子,思考下面的控制器行为:

public function getIndex()
{
    Event::fire('foo', ['name' => 'Dayle']);

    return 'All done!';
}

我们可以在 facade 上使用 shouldReceive 方法,来模拟调用 Event 类,它将会返回一个 Mockery mock 对象实例。
模拟 Facade

public function testGetIndex()
{
    Event::shouldReceive('fire')->once()->with('foo', ['name' => 'Dayle']);

    $this->call('GET', '/');
}

注意: 你不应该模拟 Request facade。取而代之,当执行你的测试,传递想要的输入数据进去 call 方法。

从测试调用路由
框架 Assertions
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

环境配置

系统服务

哈希

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }