From a1fa6ea3a3cdbf0445a50071d60eca5a82016a1e Mon Sep 17 00:00:00 2001 From: Michiel Kodde Date: Thu, 12 Sep 2024 10:56:11 +0200 Subject: [PATCH] Add a timeout helper class That is added to isolate the timeout 'business' rules are implemented correctly. And make them testable. --- src/Service/TimeoutHelper.php | 34 +++++++++++++++++++ tests/Unit/TimeoutHelperTest.php | 57 ++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 src/Service/TimeoutHelper.php create mode 100644 tests/Unit/TimeoutHelperTest.php diff --git a/src/Service/TimeoutHelper.php b/src/Service/TimeoutHelper.php new file mode 100644 index 00000000..cbe79f20 --- /dev/null +++ b/src/Service/TimeoutHelper.php @@ -0,0 +1,34 @@ += $timeoutInSeconds; + } +} diff --git a/tests/Unit/TimeoutHelperTest.php b/tests/Unit/TimeoutHelperTest.php new file mode 100644 index 00000000..feb22e86 --- /dev/null +++ b/tests/Unit/TimeoutHelperTest.php @@ -0,0 +1,57 @@ + [true, 1000, 0, 300, 2], // 100 seconds ago the user started the clock + 'just over time' => [true, 303, 0, 300, 2], // 5 seconds over timeout time + 'timeout due to offset - 1' => [true, 298, 0, 300, 2], // the offset is reached + 'timeout due to offset - 2' => [true, 299, 0, 300, 2], // the offset is reached + // In time expectations + 'very much in time' => [false, 0, 0, 300, 2], // 298 seconds to go before reaching timeout + 'just in time' => [false, 297, 0, 300, 2], // last second before reaching timeout + ]; + } +}