简体   繁体   English

如何在Symfony 2中使用Behat和Mink测试REST API

[英]How to test a REST API with Behat and Mink in Symfony 2

I'm builing a REST API in Symfony and I'd like to test it with Behat (using Mink and the behat extension for symfony2). 我正在Symfony中构建一个REST API,我想用Behat测试它(使用Mink和symfony2的behat扩展)。 There's no problem for the GET methods, I just "mock" some database objects, use the "I am on " step definition and check the response. 对于GET方法没有问题,我只是“模拟”一些数据库对象,使用“我在”步骤定义并检查响应。

But when it comes to test if the post of a certain element works I don't know how to send post params with Mink. 但是,当测试某个元素的帖子是否有效时,我不知道如何使用Mink发送post params。 I know it could be done with ie Guzzle but I think it would be much better doing it through Mink and the Symfony extension. 我知道它可以用Guzzle完成,但我认为通过Mink和Symfony扩展它会更好。

What I'm looking for is the way to define a step such as 我正在寻找的是定义诸如的步骤的方法

When I POST to <url> the following data:
| field1 | field2 | field3 |
| value1 | value2 | value3 |

Is there any easy way to send this using Mink? 有没有简单的方法使用Mink发送它? Thanks! 谢谢!

You should do it like this: 你应该这样做:

$session->getDriver()->getClient()->request ('POST', $url, $postdata);

This is what mink uses for its visit method only using get instead of post 这是mink仅使用get而不是post来visitvisit方法的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM