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

Bug with float value #8

Closed
melihovv opened this issue Jun 16, 2021 · 1 comment
Closed

Bug with float value #8

melihovv opened this issue Jun 16, 2021 · 1 comment

Comments

@melihovv
Copy link

melihovv commented Jun 16, 2021

Hi
Thanks for this awesome library, it is really cool!

I have found one bug after upgrading mcustiel/phiremock 1.12.1 to 2.1.1 and installing mcustiel/phiremock-client 1.1.2

In my code I make request with following json body {"amount": 2000.0}
I use symfony/http-client, which json encodes body with following flags JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_PRESERVE_ZERO_FRACTION (I can't change them, they are hardcoded in symfony/http-client)

In my tests I make such assertion (I use codeception)

$conditionsBuilder = ConditionsBuilder::create('get', '/some/path');
$conditionsBuilder->andBody(Is::sameJsonObjectAs(['amount' => 2000.0]));

$I->seeRemoteServiceReceived(1, $conditionsBuilder);

But it always fails.
After some debugging I realized that the problem is in \Mcustiel\Phiremock\Domain\Condition\Json. In constructor json string is decoded to array and in asString it is json_encoded again. But it json_encoded without my flags (especially JSON_PRESERVE_ZERO_FRACTION) and 2000.0 becomes 2000

Could we save original value passed in Json constructor in separate field and simply return it in asString method? That will help

@mcustiel
Copy link
Owner

mcustiel commented Jul 7, 2021

Hey @melihovv Thank you very much for reporting this and sorry for the long time it took me to fix it. Hope it works for you now.

@mcustiel mcustiel closed this as completed Jul 7, 2021
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

2 participants