Passed
Pull Request — master (#2)
by Alexander
01:40
created

TestCase::invokeMethod()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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