Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rex_timer::measure: Umgang mit Exceptions (#3173)
- Loading branch information
1 parent
b98c960
commit 93e7d7f
Showing
2 changed files
with
51 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class rex_timer_test extends TestCase | ||
{ | ||
public function testMeasure(): void | ||
{ | ||
$callable = static function () { | ||
static $i = 1; | ||
return 'result'.($i++); | ||
}; | ||
|
||
$result = rex_timer::measure('test', $callable); | ||
$timing = rex_timer::$serverTimings['test']; | ||
|
||
$this->assertSame('result1', $result); | ||
$this->assertIsFloat($timing); | ||
$this->assertGreaterThan(0, $timing); | ||
|
||
$result = rex_timer::measure('test', $callable); | ||
|
||
$this->assertSame('result2', $result); | ||
$this->assertGreaterThan($timing, rex_timer::$serverTimings['test']); | ||
|
||
$exception = null; | ||
try { | ||
rex_timer::measure('test2', static function () { | ||
throw new RuntimeException(); | ||
}); | ||
} catch (Throwable $exception) { | ||
} | ||
|
||
$timing = rex_timer::$serverTimings['test']; | ||
|
||
$this->assertInstanceOf(RuntimeException::class, $exception); | ||
$this->assertIsFloat($timing); | ||
$this->assertGreaterThan(0, $timing); | ||
} | ||
} |