Make Testcase class compatible with phpunit-9.5

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2021-03-29 09:41:32 +02:00 committed by backportbot[bot]
parent a54eaeaaff
commit f600fbf364
1 changed files with 15 additions and 3 deletions

View File

@ -459,15 +459,27 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
} }
} }
protected function getGroupAnnotations(): array {
if (method_exists($this, 'getAnnotations')) {
$annotations = $this->getAnnotations();
return $annotations['class']['group'] ?? [];
}
$r = new \ReflectionClass($this);
$doc = $r->getDocComment();
preg_match_all('#@group\s+(.*?)\n#s', $doc, $annotations);
return $annotations[1] ?? [];
}
protected function IsDatabaseAccessAllowed() { protected function IsDatabaseAccessAllowed() {
// on travis-ci.org we allow database access in any case - otherwise // on travis-ci.org we allow database access in any case - otherwise
// this will break all apps right away // this will break all apps right away
if (true == getenv('TRAVIS')) { if (true == getenv('TRAVIS')) {
return true; return true;
} }
$annotations = $this->getAnnotations(); $annotations = $this->getGroupAnnotations();
if (isset($annotations['class']['group'])) { if (isset($annotations)) {
if (in_array('DB', $annotations['class']['group']) || in_array('SLOWDB', $annotations['class']['group'])) { if (in_array('DB', $annotations) || in_array('SLOWDB', $annotations)) {
return true; return true;
} }
} }