petekaner
petekaner

Reputation: 8901

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!

Upvotes: 7

Views: 5314

Answers (1)

Carlos Granados
Carlos Granados

Reputation: 11351

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

Upvotes: 13

Related Questions