Merge pull request #55358 from nextcloud/use-group-attributes

feat(test-case): allow to use PHPUnit Group attributes to mark tests requiring database
pull/55330/merge
Côme Chilliet 1 week ago committed by GitHub
commit 6181754ec8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      tests/lib/TestCase.php

@ -34,6 +34,7 @@ use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use OCP\Security\ISecureRandom;
use OCP\Server;
use PHPUnit\Framework\Attributes\Group;
if (version_compare(\PHPUnit\Runner\Version::id(), 10, '>=')) {
trait OnNotSuccessfulTestTrait {
@ -545,11 +546,22 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
$r = new \ReflectionClass($this);
$doc = $r->getDocComment();
if (class_exists(Group::class)) {
$attributes = array_map(function (\ReflectionAttribute $attribute) {
/** @var Group $group */
$group = $attribute->newInstance();
return $group->name();
}, $r->getAttributes(Group::class));
if (count($attributes) > 0) {
return $attributes;
}
}
preg_match_all('#@group\s+(.*?)\n#s', $doc, $annotations);
return $annotations[1] ?? [];
}
protected function IsDatabaseAccessAllowed() {
protected function IsDatabaseAccessAllowed(): bool {
$annotations = $this->getGroupAnnotations();
if (isset($annotations)) {
if (in_array('DB', $annotations) || in_array('SLOWDB', $annotations)) {

Loading…
Cancel
Save