Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of PHPUnit.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PHPUnit\Util;
11
 
12
use PHPUnit\Framework\Assert;
13
use PHPUnit\Framework\TestCase;
14
use ReflectionClass;
15
use ReflectionMethod;
16
 
17
/**
18
 * @internal This class is not covered by the backward compatibility promise for PHPUnit
19
 */
20
final class Reflection
21
{
22
    /**
23
     * @psalm-return list<ReflectionMethod>
24
     */
25
    public function publicMethodsInTestClass(ReflectionClass $class): array
26
    {
27
        return $this->filterMethods($class, ReflectionMethod::IS_PUBLIC);
28
    }
29
 
30
    /**
31
     * @psalm-return list<ReflectionMethod>
32
     */
33
    public function methodsInTestClass(ReflectionClass $class): array
34
    {
35
        return $this->filterMethods($class, null);
36
    }
37
 
38
    /**
39
     * @psalm-return list<ReflectionMethod>
40
     */
41
    private function filterMethods(ReflectionClass $class, ?int $filter): array
42
    {
43
        $methods = [];
44
 
45
        // PHP <7.3.5 throw error when null is passed
46
        // to ReflectionClass::getMethods() when strict_types is enabled.
47
        $classMethods = $filter === null ? $class->getMethods() : $class->getMethods($filter);
48
 
49
        foreach ($classMethods as $method) {
50
            if ($method->getDeclaringClass()->getName() === TestCase::class) {
51
                continue;
52
            }
53
 
54
            if ($method->getDeclaringClass()->getName() === Assert::class) {
55
                continue;
56
            }
57
 
58
            $methods[] = $method;
59
        }
60
 
61
        return $methods;
62
    }
63
}