Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Reflection.php

class Reflection

Same name in this branch
  1. 11.1.x core/lib/Drupal/Component/Utility/Reflection.php \Drupal\Component\Utility\Reflection

@no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit

@internal This class is not covered by the backward compatibility promise for PHPUnit

Hierarchy

  • class \PHPUnit\Util\Reflection

Expanded class hierarchy of Reflection

4 files declare their use of Reflection
DataProvider.php in vendor/phpunit/phpunit/src/Metadata/Api/DataProvider.php
HookMethods.php in vendor/phpunit/phpunit/src/Metadata/Api/HookMethods.php
TestMethodBuilder.php in vendor/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php
TestSuite.php in vendor/phpunit/phpunit/src/Framework/TestSuite.php
1 string reference to 'Reflection'
AttributeAutoconfigurationPass::process in vendor/symfony/dependency-injection/Compiler/AttributeAutoconfigurationPass.php
You can modify the container here before it is dumped to PHP code.

File

vendor/phpunit/phpunit/src/Util/Reflection.php, line 26

Namespace

PHPUnit\Util
View source
final class Reflection {
    
    /**
     * @psalm-param class-string $className
     * @psalm-param non-empty-string $methodName
     *
     * @psalm-return array{file: non-empty-string, line: non-negative-int}
     */
    public static function sourceLocationFor(string $className, string $methodName) : array {
        try {
            $reflector = new ReflectionMethod($className, $methodName);
            $file = $reflector->getFileName();
            $line = $reflector->getStartLine();
        } catch (ReflectionException) {
            $file = 'unknown';
            $line = 0;
        }
        return [
            'file' => $file,
            'line' => $line,
        ];
    }
    
    /**
     * @psalm-return list<ReflectionMethod>
     */
    public static function publicMethodsInTestClass(ReflectionClass $class) : array {
        return self::filterAndSortMethods($class, ReflectionMethod::IS_PUBLIC, true);
    }
    
    /**
     * @psalm-return list<ReflectionMethod>
     */
    public static function methodsInTestClass(ReflectionClass $class) : array {
        return self::filterAndSortMethods($class, null, false);
    }
    
    /**
     * @psalm-return list<ReflectionMethod>
     */
    private static function filterAndSortMethods(ReflectionClass $class, ?int $filter, bool $sortHighestToLowest) : array {
        $methodsByClass = [];
        foreach ($class->getMethods($filter) as $method) {
            $declaringClassName = $method->getDeclaringClass()
                ->getName();
            if ($declaringClassName === TestCase::class) {
                continue;
            }
            if ($declaringClassName === Assert::class) {
                continue;
            }
            if (!isset($methodsByClass[$declaringClassName])) {
                $methodsByClass[$declaringClassName] = [];
            }
            $methodsByClass[$declaringClassName][] = $method;
        }
        $classNames = array_keys($methodsByClass);
        if ($sortHighestToLowest) {
            $classNames = array_reverse($classNames);
        }
        $methods = [];
        foreach ($classNames as $className) {
            $methods = array_merge($methods, $methodsByClass[$className]);
        }
        return $methods;
    }

}

Members

Title Sort descending Modifiers Object type Summary
Reflection::filterAndSortMethods private static function @psalm-return list&lt;ReflectionMethod&gt;
Reflection::methodsInTestClass public static function @psalm-return list&lt;ReflectionMethod&gt;
Reflection::publicMethodsInTestClass public static function @psalm-return list&lt;ReflectionMethod&gt;
Reflection::sourceLocationFor public static function @psalm-param class-string $className
@psalm-param non-empty-string $methodName
RSS feed
Powered by Drupal