sch*_*rht 2 php api tdd phpunit laravel
我已经从 Laravel 5.0 升级到 5.1
测试套件工作正常,我可以运行 phpunit 命令。但是,当我开始使用 api 测试进行测试时,总是会遇到 foreach 错误。
class ExampleTest extends TestCase {
public function testLoginCredentials()
{
$this->post('/srv/plc/auth/login', ['data' => 'some data'])
->seeJson([
'authorized' => true,
]);
}
}
Run Code Online (Sandbox Code Playgroud)
上面看起来像文档:http : //laravel.com/docs/5.1/testing#testing-json-apis
如果我通过 phpunit 运行我的测试,我会收到以下错误:
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.
Run Code Online (Sandbox Code Playgroud)
如果我使用 $this->get 执行 get 请求,则会收到相同的错误。与其他端点相同的错误。
$this->visit 工作正常。
经过大量调试......
我真的不知道为什么 seeJson 必须是一个数组。
我预计会出现“断言错误”,而不是 foreach 错误