0
votes

I am testing an API that returns a JOSN object, while running the following:

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

getting error:

There was 1 error:

1) ExampleTest::testBasicExample ErrorException: call_user_func() expects parameter 1 to be a valid callback, no array or string given

/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 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Testing/ApplicationTrait.php:51 /var/www/html/laravel/app/tests/ExampleTest.php:16

FAILURES! Tests: 1, Assertions: 0, Errors: 1.

I just started laravel a few days ago so I might do some very basic mistakes. Please help. Thanks

2

2 Answers

0
votes

Assuming that you're trying to send a GET request at that endpoint, you're using the wrong method.

Try this:

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


}

Then you'll probably want to make use of one of Laravel's built-in JSON-testing methods: https://laravel.com/docs/5.6/http-tests#testing-json-apis

-1
votes

you might want to do this way

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

input parameters will place as the 3rd parameters, you might give it a try.