【问题标题】:Cannot Use json Method in Laravel 5.0无法在 Laravel 5.0 中使用 json 方法
【发布时间】:2018-02-10 11:26:36
【问题描述】:

在我正在学习的一篇PHPUnit测试教程中,导师使用

    $this->json('POST', "/images/{$image->id}/purchase", [
        'email' => 'abc@gmail.com',
    ]);

当我尝试在我的测试中使用相同的代码来实现时,我得到了类似的异常错误

BadMethodCallException: 'json' 方法不存在。

C:\wamp64\www\RealTesting\vendor\laracasts\integrated\src\Extensions\IntegrationTrait.php:715

我在 Laravel 5.0 文档中搜索,找不到 json 函数。 我哪里做错了?有没有办法访问json函数?

编辑

在 Laravel 5.2 文档中,有一个 json function description on how to use

但是我找不到关于 Laravel 5.0 的 json 函数

【问题讨论】:

  • 请您在此处添加您的代码/类,以便我们在正确的上下文中为您提供帮助。请edit 在此处添加有意义的代码和问题描述。发布 minimal reproducible example 来证明您的问题将帮助您获得更好的答案。谢谢!

标签: json unit-testing laravel-5


【解决方案1】:

解决方案

如果有人在 Laravel phpunit 中遇到 json post 的问题,还有另一种方法:

$response = $this->call($method, $uri, $parameters, $files, $server, $content);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-28
    • 2016-05-10
    • 2016-11-28
    • 2015-10-26
    • 2023-01-27
    • 2019-06-08
    相关资源
    最近更新 更多