wiki.techinc.nl/tests/phpunit/suites/SuiteEventsTrait.php
Daimona Eaytoy 2d6923b76c Upgrade to PHPUnit 8
Bug: T192167
Depends-On: I1bdf465ab6d5e400f64e5325bc03bd6d62f319c7
Change-Id: Ia12658554c94497a204b7f65f1a6f7b1fa0310ac
2020-01-22 15:44:18 +00:00

42 lines
831 B
PHP

<?php
use PHPUnit\Framework\TestResult;
/**
* Trait that returns to PHPUnit test suites the support for setUp/tearDown events that
* was removed in PHPUnit 8.
*
* @since 1.35
*/
trait SuiteEventsTrait {
/**
* @inheritDoc
*/
public function run( TestResult $result = null ) : TestResult {
$calls = 0;
if ( is_callable( [ $this, 'setUp' ] ) ) {
try {
$this->setUp();
} catch ( \Throwable $_ ) {
// FIXME handle
}
$calls++;
}
$res = parent::run( $result );
if ( is_callable( [ $this, 'tearDown' ] ) ) {
try {
$this->tearDown();
} catch ( \Throwable $_ ) {
// FIXME handle
}
$calls++;
}
if ( !$calls ) {
throw new LogicException(
get_class( $this )
. " uses neither setUp() nor tearDown(), so it doesn't need SuiteEventsTrait"
);
}
return $res;
}
}