Skip to content

Comparing float and intΒ #164

@oxodao

Description

@oxodao

Hi,

I'm trying to do a generic class to do unit-test of my Api-Platform endpoints. I end up iterating on all fields and using the PropertyAccessor to get the entity's value. Something looking like this:

foreach ($fields as $field => $propertyPath) {
    $value = $this->propertyAccessor->getValue($entity, $propertyPath);
    $browser->assertJsonMatches($field, $value);
}

It works well most of the time, except it requires the type to match as well, so in case of having a float in the database which contains an integer value, no separator is in the result so the value is parsed as an int by the browser which results in a failed test.

My solution is calling more or less the same as what we have in the assertJsonMatches but with equals instead of is:

 Assert::that($browser->json()->search($field))->equals($value);

It does work for my use case but I think there is a deeper problem here, since JSON doesn't have integer / float but rather numbers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions