From 7c064e360e8e475654ac40482b4d61d2dce6ad4a Mon Sep 17 00:00:00 2001 From: joyet simon <43644110+joyet-simon@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:52:46 +0100 Subject: [PATCH 1/2] feat: add isUrlRefreshRequired function --- src/Lib/IntegrationsConfigurationsUtils.php | 16 ++++++++ .../IntegrationsConfigurationsUtilsTest.php | 37 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/Lib/IntegrationsConfigurationsUtils.php create mode 100644 tests/Unit/Lib/IntegrationsConfigurationsUtilsTest.php diff --git a/src/Lib/IntegrationsConfigurationsUtils.php b/src/Lib/IntegrationsConfigurationsUtils.php new file mode 100644 index 00000000..73f69fda --- /dev/null +++ b/src/Lib/IntegrationsConfigurationsUtils.php @@ -0,0 +1,16 @@ + $oneMonthInSeconds; + } +} \ No newline at end of file diff --git a/tests/Unit/Lib/IntegrationsConfigurationsUtilsTest.php b/tests/Unit/Lib/IntegrationsConfigurationsUtilsTest.php new file mode 100644 index 00000000..c089f674 --- /dev/null +++ b/tests/Unit/Lib/IntegrationsConfigurationsUtilsTest.php @@ -0,0 +1,37 @@ +integrationsConfigurationsUtils = new IntegrationsConfigurationsUtils(); + } + + public function testNewSendIsNotNecessary() + { + $timestamp = time() - 100; + $this->assertFalse($this->integrationsConfigurationsUtils->isUrlRefreshRequired($timestamp)); + } + public function testNewSendIsNecessary() + { + $oneMonthInSecondsMoreTen = 30 * 24 * 60 * 60 + 10; // 30 jours en secondes +10 sec + $timestamp = time() - $oneMonthInSecondsMoreTen; + $this->assertTrue($this->integrationsConfigurationsUtils->isUrlRefreshRequired($timestamp)); + } + + public function testNewSendIsNecessaryWithValueNull() + { + $this->assertTrue($this->integrationsConfigurationsUtils->isUrlRefreshRequired(null)); + } +} \ No newline at end of file From c9d53b5e9268eb8b86c7d944f61dc9b5d147fcb7 Mon Sep 17 00:00:00 2001 From: joyet simon <43644110+joyet-simon@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:57:55 +0100 Subject: [PATCH 2/2] feat: make isUrlRefreshRequired static --- src/Lib/IntegrationsConfigurationsUtils.php | 2 +- .../Lib/IntegrationsConfigurationsUtilsTest.php | 16 +++------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/Lib/IntegrationsConfigurationsUtils.php b/src/Lib/IntegrationsConfigurationsUtils.php index 73f69fda..dee516c2 100644 --- a/src/Lib/IntegrationsConfigurationsUtils.php +++ b/src/Lib/IntegrationsConfigurationsUtils.php @@ -8,7 +8,7 @@ class IntegrationsConfigurationsUtils * @param int | null $lastSendTimestamp * @return bool */ - public function isUrlRefreshRequired($lastSendTimestamp) + public static function isUrlRefreshRequired($lastSendTimestamp) { $oneMonthInSeconds = 30 * 24 * 60 * 60; // 30 jours en sec return (time() - $lastSendTimestamp) > $oneMonthInSeconds; diff --git a/tests/Unit/Lib/IntegrationsConfigurationsUtilsTest.php b/tests/Unit/Lib/IntegrationsConfigurationsUtilsTest.php index c089f674..dcf5dae6 100644 --- a/tests/Unit/Lib/IntegrationsConfigurationsUtilsTest.php +++ b/tests/Unit/Lib/IntegrationsConfigurationsUtilsTest.php @@ -8,30 +8,20 @@ class IntegrationsConfigurationsUtilsTest extends TestCase { - /** - * @var IntegrationsConfigurationsUtils - */ - private $integrationsConfigurationsUtils; - - public function setUp() : void - { - $this->integrationsConfigurationsUtils = new IntegrationsConfigurationsUtils(); - } - public function testNewSendIsNotNecessary() { $timestamp = time() - 100; - $this->assertFalse($this->integrationsConfigurationsUtils->isUrlRefreshRequired($timestamp)); + $this->assertFalse(IntegrationsConfigurationsUtils::isUrlRefreshRequired($timestamp)); } public function testNewSendIsNecessary() { $oneMonthInSecondsMoreTen = 30 * 24 * 60 * 60 + 10; // 30 jours en secondes +10 sec $timestamp = time() - $oneMonthInSecondsMoreTen; - $this->assertTrue($this->integrationsConfigurationsUtils->isUrlRefreshRequired($timestamp)); + $this->assertTrue(IntegrationsConfigurationsUtils::isUrlRefreshRequired($timestamp)); } public function testNewSendIsNecessaryWithValueNull() { - $this->assertTrue($this->integrationsConfigurationsUtils->isUrlRefreshRequired(null)); + $this->assertTrue(IntegrationsConfigurationsUtils::isUrlRefreshRequired(null)); } } \ No newline at end of file