Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(test-case): allow to use PHPUnit Group attributes to mark tests …
…requiring database

Before that, only the annotation @group('DB') is possible to mark test classes as requiring the database. Now the \PHPUnit\Framework\Attributes\Group attribute can be used as long as PHPUnit 10+ is used.

Signed-off-by: Thomas Citharel <[email protected]>
  • Loading branch information
tcitworld authored and backportbot[bot] committed Oct 6, 2025
commit 4759e4651666fe81a2197a8cd80642922a87a67e
14 changes: 13 additions & 1 deletion tests/lib/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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 {
Expand Down Expand Up @@ -545,11 +546,22 @@ protected function getGroupAnnotations(): array {

$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)) {
Expand Down
Loading