Laravel 5.1 + PHPunit - API test always returns an incorrect foreach argument error

I upgraded from Laravel 5.0 to 5.1

The test suite works fine, and I can run the phpunit command. But, when I start testing with the api test, I always get a foreach error.

class ExampleTest extends TestCase {

    public function testLoginCredentials()
    {
        $this->post('/srv/plc/auth/login', ['data' => 'some data'])
        ->seeJson([
            'authorized' => true,
        ]);
    }
}

The above documentation looks like: http://laravel.com/docs/5.1/testing#testing-json-apis

If I run my test through phpunit, I get the following error:

There was 1 error:

1) ExampleTest::testBasicExample
ErrorException: Invalid argument supplied for foreach()
/Applications/XAMPP/xamppfiles/htdocs/w/server/vendor/framework/src/Illuminate/Support/Arr.php:423
/Applications/XAMPP/xamppfiles/htdocs/w/server/vendor/framework/src/Illuminate/Support/helpers.php:301
/Applications/XAMPP/xamppfiles/htdocs/w/server/vendor/framework/src/Illuminate/Foundation/Testing/CrawlerTrait.php:365
/Applications/XAMPP/xamppfiles/htdocs/whennn/server/vendor/laravel/framework/src/Illuminate/Foundation/Testing/CrawlerTrait.php:352
/Applications/XAMPP/xamppfiles/htdocs/whennn/server/tests/ExampleTest.php:17
/Applications/XAMPP/xamppfiles/lib/php/PHPUnit/TextUI/Command.php:188
/Applications/XAMPP/xamppfiles/lib/php/PHPUnit/TextUI/Command.php:126

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

If I get a request with $ this-> get, I get the same error. Same error with other endpoints.

$ this-> works great.

+2
source share
1 answer

After a lot of debugging ....

  • seeJson() Json ( Json)
  • , . , , .

, seeJson .

" " foreach

+4

All Articles