我正在尝试向TestReponse
类添加自定义断言,以便我可以创建如下代码:
$response = $this->json('POST', '/foo/bar');
$response->myCustomAssertion();
我尝试创建了一个扩展原有类的
App\TestResponse
类,并在 App\Provider\AppServiceProvider
类中进行绑定。public function register()
{
$this->app->bind('Illuminate\Foundation\Testing\TestResponse', function ($app) {
return new App\TestResponse();
});
}
但是$response->json()
仍然返回原始结果,而不是我的自定义实现。
我该如何扩展TestResponse
类?
macro
调用来在运行时添加方法。 - lagbox