Skip to content

Instantly share code, notes, and snippets.

@ismail1432
Last active August 18, 2022 17:23
Show Gist options
  • Save ismail1432/0e4d6159bfb86205751ca6c7363290ec to your computer and use it in GitHub Desktop.
Save ismail1432/0e4d6159bfb86205751ca6c7363290ec to your computer and use it in GitHub Desktop.
<?php
namespace App\Test;
use App\Test\TimeoutMaxDuration;
use PHPUnit\Framework\TestCase;
use PHPUnit\Runner\AfterTestHook;
class TimeoutPHPUnitExtension extends TestCase implements AfterTestHook
{
public function executeAfterTest(string $test, float $time): void
{
$maxDuration = TimeoutMaxDuration::$timeout;
self::assertLessThan(TimeoutTest::$timeout, $time,
sprintf('The test "%s" was too long, it tooks "%f" seconds and the maximum allowed is "%d"',
$test,
$time,
$maxDuration
)
);
TimeoutTest::resetTimeout();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment