diff options
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/TestCase.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php index 03886d4a0be..d74dacd76c1 100644 --- a/tests/lib/TestCase.php +++ b/tests/lib/TestCase.php @@ -271,6 +271,30 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase { ); } + /** + * Filter methods + * + * Returns all methods of the given class, + * that are public or abstract and not in the ignoreMethods list, + * to be able to fill onlyMethods() with an inverted list. + * + * @param string $className + * @param string[] $filterMethods + * @return string[] + */ + public function filterClassMethods(string $className, array $filterMethods): array { + $class = new \ReflectionClass($className); + + $methods = []; + foreach ($class->getMethods() as $method) { + if (($method->isPublic() || $method->isAbstract()) && !in_array($method->getName(), $filterMethods, true)) { + $methods[] = $method->getName(); + } + } + + return $methods; + } + public static function tearDownAfterClass(): void { if (!self::$wasDatabaseAllowed && self::$realDatabase !== null) { // in case an error is thrown in a test, PHPUnit jumps straight to tearDownAfterClass, |