Skip to content

Commit

Permalink
Fix micro-second approximation test for PHP 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Oct 9, 2024
1 parent 26401dd commit dd38f9d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/CarbonInterval/ConstructTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ public function testFromSerialization()
$this->assertSameIntervals($interval, $copy, 1);
}

/** @group i */
public function testFromSerializationConst()
{
$past = new Carbon('2024-01-01 00:00:00');
Expand Down Expand Up @@ -538,6 +539,18 @@ private function assertSameIntervals(CarbonInterval $expected, CarbonInterval $a
$actualProperties = (array) $actual;
unset($actualProperties['days']);

if (
$expectedProperties["\0*\0rawInterval"]->f !== $actualProperties["\0*\0rawInterval"]->f
&& $microsecondApproximation > 0
&& $actualProperties["\0*\0rawInterval"]->f >= $expectedProperties["\0*\0rawInterval"]->f - $microsecondApproximation
&& $actualProperties["\0*\0rawInterval"]->f <= $expectedProperties["\0*\0rawInterval"]->f + $microsecondApproximation
) {
unset($expectedProperties["\0*\0rawInterval"]);
unset($expectedProperties["\0*\0originalInput"]);
unset($actualProperties["\0*\0rawInterval"]);
unset($actualProperties["\0*\0originalInput"]);
}

$this->assertEquals($expectedProperties, $actualProperties);
}
}

0 comments on commit dd38f9d

Please sign in to comment.