lundi 18 juin 2018

Assert an object value is within a range in PHPUnit

I'm fairly new to using PHPUnit, so I hope this isn't a time-wasting question:

I have a set of tests which assert equals on an object.

The issue is when the dates are set, the date/time might be off by 1 second. I know it is possible to assert a value is between two values, like so:

$this->assertThat(
    $testFloat,
    $this->logicalAnd(
        $this->greaterThan(1.65),
        $this->lessThan(1.66)
    )
);

However, my value resides inside an object, so my assertEquals fails.

Can anybody help, or give some clues how to work around this?

Aucun commentaire:

Enregistrer un commentaire