mirror of
https://github.com/nextcloud/server.git
synced 2026-05-19 08:25:56 -04:00
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 <tcit@tcit.fr>
This commit is contained in:
parent
a0fd63155b
commit
cad9728db7
1 changed files with 13 additions and 1 deletions
|
|
@ -26,6 +26,7 @@ use OCP\IDBConnection;
|
|||
use OCP\IL10N;
|
||||
use OCP\Lock\ILockingProvider;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
|
||||
if (version_compare(\PHPUnit\Runner\Version::id(), 10, '>=')) {
|
||||
trait OnNotSuccessfulTestTrait {
|
||||
|
|
@ -529,11 +530,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…
Reference in a new issue