class ResultCacheHandler
@no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
@internal This class is not covered by the backward compatibility promise for PHPUnit
Hierarchy
- class \PHPUnit\Runner\ResultCache\ResultCacheHandler
Expanded class hierarchy of ResultCacheHandler
1 file declares its use of ResultCacheHandler
- Application.php in vendor/
phpunit/ phpunit/ src/ TextUI/ Application.php
File
-
vendor/
phpunit/ phpunit/ src/ Runner/ ResultCache/ ResultCacheHandler.php, line 33
Namespace
PHPUnit\Runner\ResultCacheView source
final class ResultCacheHandler {
private readonly ResultCache $cache;
private ?HRTime $time = null;
private int $testSuite = 0;
/**
* @throws EventFacadeIsSealedException
* @throws UnknownSubscriberTypeException
*/
public function __construct(ResultCache $cache, Facade $facade) {
$this->cache = $cache;
$this->registerSubscribers($facade);
}
public function testSuiteStarted() : void {
$this->testSuite++;
}
public function testSuiteFinished() : void {
$this->testSuite--;
if ($this->testSuite === 0) {
$this->cache
->persist();
}
}
public function testPrepared(Prepared $event) : void {
$this->time = $event->telemetryInfo()
->time();
}
public function testMarkedIncomplete(MarkedIncomplete $event) : void {
$this->cache
->setStatus($event->test()
->id(), TestStatus::incomplete($event->throwable()
->message()));
}
public function testConsideredRisky(ConsideredRisky $event) : void {
$this->cache
->setStatus($event->test()
->id(), TestStatus::risky($event->message()));
}
public function testErrored(Errored $event) : void {
$this->cache
->setStatus($event->test()
->id(), TestStatus::error($event->throwable()
->message()));
}
public function testFailed(Failed $event) : void {
$this->cache
->setStatus($event->test()
->id(), TestStatus::failure($event->throwable()
->message()));
}
/**
* @throws \PHPUnit\Event\InvalidArgumentException
* @throws InvalidArgumentException
*/
public function testSkipped(Skipped $event) : void {
$this->cache
->setStatus($event->test()
->id(), TestStatus::skipped($event->message()));
$this->cache
->setTime($event->test()
->id(), $this->duration($event));
}
/**
* @throws \PHPUnit\Event\InvalidArgumentException
* @throws InvalidArgumentException
*/
public function testFinished(Finished $event) : void {
$this->cache
->setTime($event->test()
->id(), $this->duration($event));
$this->time = null;
}
/**
* @throws \PHPUnit\Event\InvalidArgumentException
* @throws InvalidArgumentException
*/
private function duration(Event $event) : float {
if ($this->time === null) {
return 0.0;
}
return round($event->telemetryInfo()
->time()
->duration($this->time)
->asFloat(), 3);
}
/**
* @throws EventFacadeIsSealedException
* @throws UnknownSubscriberTypeException
*/
private function registerSubscribers(Facade $facade) : void {
$facade->registerSubscribers(new TestSuiteStartedSubscriber($this), new TestSuiteFinishedSubscriber($this), new TestPreparedSubscriber($this), new TestMarkedIncompleteSubscriber($this), new TestConsideredRiskySubscriber($this), new TestErroredSubscriber($this), new TestFailedSubscriber($this), new TestSkippedSubscriber($this), new TestFinishedSubscriber($this));
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
ResultCacheHandler::$cache | private | property | |
ResultCacheHandler::$testSuite | private | property | |
ResultCacheHandler::$time | private | property | |
ResultCacheHandler::duration | private | function | |
ResultCacheHandler::registerSubscribers | private | function | |
ResultCacheHandler::testConsideredRisky | public | function | |
ResultCacheHandler::testErrored | public | function | |
ResultCacheHandler::testFailed | public | function | |
ResultCacheHandler::testFinished | public | function | |
ResultCacheHandler::testMarkedIncomplete | public | function | |
ResultCacheHandler::testPrepared | public | function | |
ResultCacheHandler::testSkipped | public | function | |
ResultCacheHandler::testSuiteFinished | public | function | |
ResultCacheHandler::testSuiteStarted | public | function | |
ResultCacheHandler::__construct | public | function |