简体   繁体   中英

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). 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.

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. 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.

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? 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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