From f600fbf364a22783234660d9db4f37e491dd9179 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 29 Mar 2021 09:41:32 +0200 Subject: [PATCH] Make Testcase class compatible with phpunit-9.5 Signed-off-by: Joas Schilling --- tests/lib/TestCase.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php index 6cadf9693c..066a7d5b13 100644 --- a/tests/lib/TestCase.php +++ b/tests/lib/TestCase.php @@ -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() { // on travis-ci.org we allow database access in any case - otherwise // this will break all apps right away if (true == getenv('TRAVIS')) { return true; } - $annotations = $this->getAnnotations(); - if (isset($annotations['class']['group'])) { - if (in_array('DB', $annotations['class']['group']) || in_array('SLOWDB', $annotations['class']['group'])) { + $annotations = $this->getGroupAnnotations(); + if (isset($annotations)) { + if (in_array('DB', $annotations) || in_array('SLOWDB', $annotations)) { return true; } }