Created
May 3, 2022 12:48
-
-
Save innocenzi/f769e14097faf8d623ead42b81ddbf6b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
namespace Tests; | |
/** @mixin TestCase */ | |
trait BenchmarksTests | |
{ | |
protected static array $tests = []; | |
protected function setUpBenchmark(): void | |
{ | |
self::$tests[$this->getTestName()] = now(); | |
} | |
public static function tearDownAfterClass(): void | |
{ | |
arsort(self::$tests); | |
file_put_contents('.phpunit_benchmark', json_encode(self::$tests)); | |
} | |
protected function tearDown(): void | |
{ | |
parent::tearDown(); | |
self::$tests[$this->getTestName()] = self::$tests[$this->getTestName()]->diffInMilliseconds(); | |
} | |
protected function getTestName(): string | |
{ | |
return static::class.'::'.$this->getName(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment