Ste*_*gin 1 phpunit codeception web-api-testing
当使用带有PhpBrowser驱动程序的REST模块通过代码接收测试发出请求时,没有数据和文件通过Silex应用程序。
// ApiTester $I
$I->wantTo('Submit files');
// prepare:
$data = ['key' => 'value'];
$files = [
'file_key' => 'path/to/file.doc',
'file2_key' => 'path/to/file2.doc'
];
// act:
$I->haveHttpHeader('Content-Type', 'multipart/form-data');
$I->sendPOST('/attachments/', $data, $files);
Run Code Online (Sandbox Code Playgroud)
I have http header "Content-Type","multipart/form-data"
I send post "/attachments/",{"key":"value"},{"file_key":"/path/to/file/...}
[Request] POST http://localhost/attachments/ {"key":"value"}
[Request Headers] {"Content-Type":"multipart/form-data"}
[Page] http://localhost/attachments/
[Response] 400
[Request Cookies] []
[Response Headers] {"Date":["Tue, 25 Oct 2016 09:15:31 GMT"],"Server":["Apache/2.4.10 (Debian)"],"Cache-Control":["no-cache"],"Access-Control-Allow-Origin":["*"],"Access-Control-Allow-Headers":["Content-Type, Authorization"],"Access-Control-Allow-Methods":["GET,PATCH,PUT,POST,HEAD,DELETE,OPTIONS"],"Content-Length":["1235"],"Connection":["close"],"Content-Type":["application/json"]}
[Response] {"status":400,"meta":{"time":"2016-10-25 09:15:31"},"title":"Invalid Request","errors":"No data received","details":{"error_class":"Symfony\Component\HttpKernel\Exception\BadRequestHttpException"
Run Code Online (Sandbox Code Playgroud)
该测试可与Silex驱动程序一起使用,但在CI服务器上将不可选。我们还检查了Postman,API路由按预期工作,文件已发送且一切正常。