Passed
Push — master ( 0ba500...61251f )
by Alexander
02:59
created

TestCase::invokeMethod()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 12
rs 10
cc 2
nc 2
nop 4
1
<?php
2
declare(strict_types=1);
3
4
namespace Yiisoft\Profiler\Tests;
5
6
use Yiisoft\Profiler\Tests\Logger\ArrayLogger;
7
8
abstract class TestCase extends \PHPUnit\Framework\TestCase
9
{
10
    protected ArrayLogger $logger;
11
12
    protected function setUp(): void
13
    {
14
        parent::setUp();
15
16
        $this->logger = new ArrayLogger();
17
    }
18
19
    /**
20
     * Invokes a inaccessible method.
21
     *
22
     * @param object $object
23
     * @param string $method
24
     * @param array $args
25
     * @param bool $revoke whether to make method inaccessible after execution
26
     *
27
     * @return mixed
28
     */
29
    protected function invokeMethod($object, $method, $args = [], $revoke = true)
30
    {
31
        $reflection = new \ReflectionObject($object);
32
        $method = $reflection->getMethod($method);
33
        $method->setAccessible(true);
34
        $result = $method->invokeArgs($object, $args);
35
36
        if ($revoke) {
37
            $method->setAccessible(false);
38
        }
39
40
        return $result;
41
    }
42
}
43