Behatch / contexts

Behat extension with most custom helper steps
Other
393 stars 203 forks source link

Rest Context - Send Request with Parameters Bug #256

Closed mab05k closed 6 years ago

mab05k commented 6 years ago

I am attempting to use the Gherkin statement @Given I send a :method request to :url with parameters:. I have a query parameter that has a . in it, item.id, so I create the table node like this

Then I send a "GET" request to "/endpoint" with parameters:
| key        | value |
| item.id    | 1     |

The function uses this snippet:

parse_str(implode('&', $parameters), $parameters);

which transforms my query parameter to item_id and my API ignores this and tests don't run properly. The function parse_str cannot create variables with a . because this is illegal in PHP.

The snippet that creates the $parameters array could be updated from

$parameters[] = sprintf('%s=%s', $row['key'], $row['value']);

to

$parameters[$row['key']] = $row['value'];

and we can remove this (which seems to be an unnecessary manipulation of the data passed into the function)

parse_str(implode('&', $parameters), $parameters);
sanpii commented 6 years ago

Your suggestion is a good idea, but it probably doesn’t resolve your issue: the parameters is not sent for GET and HEAD requests https://github.com/FriendsOfPHP/Goutte/blob/master/Goutte/Client.php#L152

mab05k commented 6 years ago

I see. However, I'm using the Symfony2Extension, so we're using the Symfony Client for the requests which doesn't exclude GET and HEAD.

https://github.com/symfony/http-kernel/blob/master/Client.php#L68

Could this change potentially break something for Goutte? I'm not familiar enough with it.

sanpii commented 6 years ago

Can you test this modification https://github.com/Behatch/contexts/pull/258 ?

mab05k commented 6 years ago

Sorry for the delay @sanpii . Works as expected, thanks!!

cdaguerre commented 5 years ago

Unfortunately this broke the ability to send array parameters in get requests, which worked before, eg.

Given I send a "GET" request to "/some-url" with parameters:
  | key      | value |
  | param1   | val1  |
  | param2[] | val2  |

is now equivalent to:

$parameters = ['param1' => 'val1', 'param2[]' => 'val2'];

while before this translated to:

$parameters = ['param1' => 'val1', 'param2' => [0 => 'val2']];