diff --git a/src/Utils.php b/src/Utils.php index d9bec28..d885c80 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -38,7 +38,7 @@ public static function transformCurrencies(array $currencies): array public static function countTTL(DateTime $dateTime, int $beforeExpiration = 900): int { $time = time(); - if (($dateTime->getTimestamp() - $beforeExpiration) < $time) { + if (($dateTime->getTimestamp() - $beforeExpiration) <= $time) { $dateTime->modify('+1 day'); } diff --git a/tests/src/UtilsTest.php b/tests/src/UtilsTest.php new file mode 100644 index 0000000..71d1fe5 --- /dev/null +++ b/tests/src/UtilsTest.php @@ -0,0 +1,62 @@ + + */ + public function data(): array + { + return [ + [ + function (self $self) { + $self->assert( + 901, + new DateTime('+901 seconds'), + ); + }, + ], + [ + function (self $self) { + $self->assert( + 87300, + new DateTime('+900 seconds'), + ); + }, + ], + ]; + } + + + /** + * @param Closure(static):void $assert + * @dataProvider data + */ + public function testCountTTL(Closure $assert): void + { + $assert($this); + } + + + public function assert( + int $expectedTime, + DateTime $from + ): void + { + Assert::same($expectedTime, Utils::countTTL($from)); + } +} + +(new UtilsTest())->run();