Skip to content

Commit

Permalink
Merge pull request #1333 from hydephp/fix-tests
Browse files Browse the repository at this point in the history
Create test class with fixed data to prevent false test failures
  • Loading branch information
caendesilva committed Mar 18, 2023
2 parents bd6b240 + 09fb435 commit f780285
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/framework/tests/Unit/TracksExecutionTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand All @@ -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;
}
}

0 comments on commit f780285

Please sign in to comment.