From 09fb435b58055a5cd24170773229422321d8ee68 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 18 Mar 2023 19:09:17 +0100 Subject: [PATCH] Create test class with fixed data to prevent false test failures --- .../tests/Unit/TracksExecutionTimeTest.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/framework/tests/Unit/TracksExecutionTimeTest.php b/packages/framework/tests/Unit/TracksExecutionTimeTest.php index 7ef6231b7a0..44752ba2816 100644 --- a/packages/framework/tests/Unit/TracksExecutionTimeTest.php +++ b/packages/framework/tests/Unit/TracksExecutionTimeTest.php @@ -36,21 +36,18 @@ public function test_stopClock() public function test_getExecutionTimeInMs() { - $class = new TracksExecutionTimeTestClass(); - $class->startClock(); + $class = new FixedStopClockTestClass(); $this->assertIsFloat($class->getExecutionTimeInMs()); - $this->assertLessThan(1, $class->getExecutionTimeInMs()); + $this->assertSame(3.14, $class->getExecutionTimeInMs()); } public function test_getExecutionTimeString() { - $class = new TracksExecutionTimeTestClass(); - $class->startClock(); + $class = new FixedStopClockTestClass(); $this->assertIsString($class->getExecutionTimeString()); - $this->assertTrue(str_starts_with($class->getExecutionTimeString(), '0')); - $this->assertTrue(str_ends_with($class->getExecutionTimeString(), 'ms')); + $this->assertSame('3.14ms', $class->getExecutionTimeString()); } } @@ -73,3 +70,11 @@ public function isset(string $name): bool return isset($this->$name); } } + +class FixedStopClockTestClass extends TracksExecutionTimeTestClass +{ + protected function stopClock(): float + { + return 3.14 / 1000; + } +}