Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lib/InnerBrowser] Send raw content in post body #61

Open
krukru opened this issue Sep 11, 2019 · 4 comments
Open

[Lib/InnerBrowser] Send raw content in post body #61

krukru opened this issue Sep 11, 2019 · 4 comments

Comments

@krukru
Copy link

krukru commented Sep 11, 2019

What are you trying to achieve?

I am trying to call sendAjaxPostRequest and I would like to pass raw, unformatted parameters to the server.
For example

$I->sendAjaxPostRequest('/some-endpoint', '{"foo": "bar"}');
// or even
$I->sendAjaxPostRequest('/some-endpoint', 'hello, how do you do?')

What do you get instead?

I get an error saying that the second parameter of sendAjaxPostRequest must be of type array. This array then gets converted using http_build_query and there is no way to pass raw data. See https://github.com/Codeception/Codeception/blob/3.1/src/Codeception/Lib/InnerBrowser.php#L189

When passing an array, the array always gets converted to http query params format of foo=bar&example=codeception

I think an alternative approach could be to use REST Module, which I think can accept raw content (or at least properly json_encode body).

Is there something I am missing? How would you suggest to test this endpoint?

@Naktibalda
Copy link
Member

REST methods are more flexible in that regard, they send $parameters parameter as-is if it isn't an array.

@krukru
Copy link
Author

krukru commented Sep 16, 2019

Thanks @Naktibalda, does this mean there are no plans for adding this feature in the InnerBrowser module? I could help out with writing a PR if you could just push me in the right direction. Would it be acceptable to refactor the inner browser method to behave exactly like in the REST module (send as-if if isn't array and keep current behaviour if param is array)

@Naktibalda
Copy link
Member

You are welcome to make a pull request, though now isn't the best time for it.
Unless you want to make it straight to https://github.com/Codeception/lib-innerbrowser/ which will be released with Codeception 4, probably next month.

@reinholdfuereder
Copy link
Contributor

I was just about to file a new issue "Support sendPOST with raw body content AND query parameters [REST module]", but am hesitating now...

Cf. comment by @davidjeddy in Codeception/Codeception#375 (comment)

I too ran into something like this. In order to pass content-Body I could not use the send parameter of sendPUT as the query string. We had to create the entire URL in the first param with the second param acting as the body content.

@krukru Therefore I think "refactor the inner browser method to behave exactly like in the REST module (send as-if if isn't array and keep current behaviour if param is array)" is not a good idea -- unless I misunderstand you and your goal is support for sending requests with raw body content AND query parameters at the same time...

Related issues:

@Naktibalda (Unrelated to this issue, but...) Because you just mentioned Codeception 4 to be released soon: Would it please be possible to merge my recent little PRs (Codeception/phpunit-wrapper#62 + Codeception/Codeception#5690; Codeception/Codeception#5688) for 2 IMHO rather bad Codeception bugs before and soon release them in a (last?) 3.1.x version; and of course also merge them into new Codeception 4 codebase? (This would be very motivating and also promising with respect to the future usage of Codeception...) Thanks!

@Naktibalda Naktibalda transferred this issue from Codeception/Codeception Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants