Skip to content

Instantly share code, notes, and snippets.

@innocenzi
Created May 3, 2022 12:48
Show Gist options
  • Save innocenzi/f769e14097faf8d623ead42b81ddbf6b to your computer and use it in GitHub Desktop.
Save innocenzi/f769e14097faf8d623ead42b81ddbf6b to your computer and use it in GitHub Desktop.
<?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