gpt4 book ai didi

php - Symfony 功能测试 JSON

转载 作者:行者123 更新时间:2023-11-28 21:34:11 26 4
gpt4 key购买 nike

如果操作返回 json 对象,我如何在 Symfony 功能测试中测试响应?

我有密码

with('response')->begin()->   isHeader('content-type','application/json')->end();

但是测试总是失败。

最佳答案

以下 URL 可能会向您展示如何对其进行测试:Practical symfony Day 15: Web Services

这是该页面的相关代码:

$browser->
info('1 - Web service security')->

info(' 1.1 - A token is needed to access the service')->
get('/api/foo/jobs.xml')->
with('response')->isStatusCode(404)->

info(' 1.2 - An inactive account cannot access the web service')->
get('/api/symfony/jobs.xml')->
with('response')->isStatusCode(404)->

info('2 - The jobs returned are limited to the categories configured for the affiliate')->
get('/api/sensio_labs/jobs.xml')->
with('request')->isFormat('xml')->
with('response')->begin()->
isValid()->
checkElement('job', 32)->
end()->

info('3 - The web service supports the JSON format')->
get('/api/sensio_labs/jobs.json')->
with('request')->isFormat('json')->
with('response')->matches('/"category"\: "Programming"/')->

info('4 - The web service supports the YAML format')->
get('/api/sensio_labs/jobs.yaml')->
with('response')->begin()->
isHeader('content-type', 'text/yaml; charset=utf-8')->
matches('/category\: Programming/')->
end()
;

关于php - Symfony 功能测试 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6248010/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com