From 48b004d1fedd8b6a3fffb7fce9da94541833cd67 Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Fri, 16 Apr 2021 22:31:14 -0400 Subject: [PATCH] avoid problems --- Civi/Test/GenericAssertionsTrait.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Civi/Test/GenericAssertionsTrait.php b/Civi/Test/GenericAssertionsTrait.php index 8d04b6359b..d5a4557ede 100644 --- a/Civi/Test/GenericAssertionsTrait.php +++ b/Civi/Test/GenericAssertionsTrait.php @@ -57,6 +57,10 @@ trait GenericAssertionsTrait { * @param string $message */ public function assertApproxEquals($expected, $actual, $tolerance, $message = NULL) { + if ($tolerance == 1 && is_int($expected) && is_int($actual)) { + // ^^ loose equality is on purpose + throw new \CRM_Core_Exception('assertApproxEquals is a fractions-first thinking function and compares integers with a tolerance of 1 as if they are identical. You want a bigger number, such as 2, or 5.'); + } $diff = abs($actual - $expected); if ($message === NULL) { $message = sprintf("approx-equals: expected=[%.3f] actual=[%.3f] diff=[%.3f] tolerance=[%.3f]", $expected, $actual, $diff, $tolerance); -- 2.25.1