首页 文章

call_user_func()期望参数1是有效的回调 - Laravel单元测试

提问于
浏览
0

我正在测试返回JOSN对象的API,同时运行以下命令:

public function testBasicExample()
    {
        $response = $this->call('GET', 'sites/1/webmaster/totalstats?since=2014-01-01&until=2014-12-30');
    }

得到错误:

有1个错误:1)ExampleTest :: testBasicExample ErrorException:call_user_func()期望参数1是有效的回调,没有给出的数组或字符串/var/www/html/laravel/app/facade/Webmaster.php:527 / var / www / html / laravel / app / helpers / WebmasterHelper.php:100 /var/www/html/laravel/app/controllers/WebmasterController.php:129 /var/www/html/laravel/app/routes.php: 73 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Routing/Route.php:109 / var / www / html / laravel / vendor / laravel / framework / src / Illuminate / Routing / Router . php:1033 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1001 / var / www / html / laravel / vendor / laravel / framework / src / Illuminate / Foundation / Application.php:775 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:745 / var / www / html / laravel / vendor / symfony / http-kernel / Symfony / Component / HttpKernel / Client.php:81 /var/www/html/laravel/vendor/symfony/browser-kit/Symfony/Component/BrowserKit/Client.php:327 / v ar / www / html / laravel / vendor / laravel / framework / src / Illuminate / Foundation / Testing / ApplicationTrait.php:51 /var/www/html/laravel/app/tests/ExampleTest.php:16失败!测试:1,断言:0,错误:1 .

我几天前刚开始拉扯,所以我可能会犯一些非常基本的错误 . 请帮忙 . 谢谢

2 回答

  • 0

    假设您正在尝试在该 endpoints 发送GET请求,那么您使用的方法是错误的 .

    试试这个:

    public function testBasicExample()
    {
        $response = $this->get('/sites/1/webmaster/totalstats?since=2014-01-01&until=2014-12-30');
    
    
    }
    

    然后你'll probably want to make use of one of Laravel'的内置JSON测试方法:https://laravel.com/docs/5.6/http-tests#testing-json-apis

  • -1

    你可能想这样做

    $response = $this->call('GET', 'sites/1/webmaster/totalstats', [
            'since' => '2014-01-01',
            'until' => '2014-12-30'
        ]);
    

    输入参数将作为第3个参数放置,您可以尝试一下 .

相关问题