Codeception / module-rest

REST module for Codeception
MIT License
53 stars 27 forks source link

[ feature request ] Support flags for json_encode() function #51

Closed charescape closed 3 years ago

charescape commented 3 years ago

currently, encodeApplicationJson use json_encode() without flags, is there any way to add default flags like:

if ($parameters instanceof \JsonSerializable) {
    return json_encode($parameters, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
if (is_array($parameters) || $parameters instanceof \ArrayAccess) {
    $parameters = $this->scalarizeArray($parameters);
    return json_encode($parameters, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}

https://github.com/Codeception/module-rest/blob/e314fe772c84ab1f2c0b80f435cc90efa58e7209/src/Codeception/Module/REST.php#L676-L692

Naktibalda commented 3 years ago

Yes, you can raise pull request :)

What issue would it solve for you?

charescape commented 3 years ago

@Naktibalda It can testing some edge cases,

for example:

JSON_INVALID_UTF8_IGNORE

Ignore invalid UTF-8 characters. Available as of PHP 7.2.0.

JSON_INVALID_UTF8_SUBSTITUTE

Convert invalid UTF-8 characters to \0xfffd (Unicode Character 'REPLACEMENT CHARACTER') Available as of PHP 7.2.0.

https://www.php.net/manual/en/json.constants.php

charescape commented 3 years ago

@Naktibalda And I have been busy recently, but I will try to submit a PR as soon as possible :)

Naktibalda commented 3 years ago

If you need to test that, you can use your own json_encode function.

Change $I->sendPost($uri, $data); to $I->sendPost($uri, json_encode($data, JSON_INVALID_UTF8_IGNORE));

charescape commented 3 years ago

So, $params can be a string?

charescape commented 3 years ago

Yes, found it: https://github.com/Codeception/module-rest/blob/master/src/Codeception/Module/REST.php#L696

charescape commented 3 years ago

Thank you!