【问题标题】:How to set global header in Laravel TestCase?如何在 Laravel TestCase 中设置全局标题?
【发布时间】:2016-07-11 23:48:29
【问题描述】:

我正在使用内置的 Laravel TestCase 来测试我的 REST API。
每个端点都需要 Accept:application/json 标头。

如何为TestCase 中的每个响应全局设置此标头?

【问题讨论】:

    标签: laravel testing laravel-5 phpunit


    【解决方案1】:

    只需使用json 方法。它会自动为您设置标题,您可以像这样使用它。

    $this->json('GET', 'my-end-point');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-13
      • 1970-01-01
      • 1970-01-01
      • 2017-05-01
      • 1970-01-01
      • 2020-11-18
      相关资源
      最近更新 更多