Skip to content

Commit aa36f1c

Browse files
Merge pull request #55571 from nextcloud/backport/55358/stable32
[stable32] feat(test-case): allow to use PHPUnit Group attributes to mark tests requiring database
2 parents 5678b63 + 4759e46 commit aa36f1c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tests/lib/TestCase.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use OCP\Lock\LockedException;
3535
use OCP\Security\ISecureRandom;
3636
use OCP\Server;
37+
use PHPUnit\Framework\Attributes\Group;
3738

3839
if (version_compare(\PHPUnit\Runner\Version::id(), 10, '>=')) {
3940
trait OnNotSuccessfulTestTrait {
@@ -545,11 +546,22 @@ protected function getGroupAnnotations(): array {
545546

546547
$r = new \ReflectionClass($this);
547548
$doc = $r->getDocComment();
549+
550+
if (class_exists(Group::class)) {
551+
$attributes = array_map(function (\ReflectionAttribute $attribute) {
552+
/** @var Group $group */
553+
$group = $attribute->newInstance();
554+
return $group->name();
555+
}, $r->getAttributes(Group::class));
556+
if (count($attributes) > 0) {
557+
return $attributes;
558+
}
559+
}
548560
preg_match_all('#@group\s+(.*?)\n#s', $doc, $annotations);
549561
return $annotations[1] ?? [];
550562
}
551563

552-
protected function IsDatabaseAccessAllowed() {
564+
protected function IsDatabaseAccessAllowed(): bool {
553565
$annotations = $this->getGroupAnnotations();
554566
if (isset($annotations)) {
555567
if (in_array('DB', $annotations) || in_array('SLOWDB', $annotations)) {

0 commit comments

Comments
 (0)