Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 i.e. 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!

like image 940
petekaner Avatar asked Oct 26 '15 20:10

petekaner


1 Answers

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

like image 124
Carlos Granados Avatar answered Nov 15 '22 00:11

Carlos Granados