7

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!

petekaner
  • 8,071
  • 5
  • 29
  • 52
  • @CarlosGranados yep, I already read that article. The problem is that makes a simple post request and I'd like to make an internal request the way mink does with symfony – petekaner Oct 26 '15 at 21:14
  • [Api request response testing with behat v2 includes json, xml, html and cli](http://www.inanzzz.com/index.php/post/ajqn/api-request-response-testing-with-behat-v2-includes-json-xml-html-and-cli) and [Api request response testing with behat v1](http://www.inanzzz.com/index.php/post/xw1v/api-request-response-testing-with-behat-v1) – BentCoder Oct 27 '15 at 14:45

1 Answers1

13

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

Carlos Granados
  • 11,273
  • 1
  • 38
  • 44
  • What is the format of the $postdata? Is it key=>value array? – osantos Sep 30 '16 at 14:36
  • The $postdata signature is in the symfony/browser-kit/Client.php. Yes, $postdata is an associative array. – Everett Jun 21 '17 at 20:18
  • @KonstantinPereiaslov BrowserKit driver also supports POST. https://github.com/minkphp/MinkBrowserKitDriver/blob/master/src/BrowserKitDriver.php#L144 – Leevi Graham May 01 '18 at 10:36