Passed
Pull Request — master (#2)
by Wilmer
01:23
created

TestCase   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
eloc 14
c 3
b 0
f 0
dl 0
loc 57
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A tearDown() 0 3 1
A invokeMethod() 0 12 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Yiisoft\Profiler\Tests;
5
6
use Psr\Log\LoggerInterface;
7
use Yiisoft\Factory\Factory;
8
use Yiisoft\Profiler\Tests\Logger\ArrayLogger;
9
10
abstract class TestCase extends \PHPUnit\Framework\TestCase
11
{
12
    /**
13
     * @var Factory $factory
14
     */
15
    protected Factory $factory;
16
17
    /**
18
     * @var ArrayLogger $logger
19
     */
20
    protected ArrayLogger $logger;
21
22
    /**
23
     * setUp
24
     *
25
     * @return void
26
     */
27
    protected function setUp(): void
28
    {
29
        parent::setUp();
30
31
        $this->factory = new Factory();
32
        $this->logger = new ArrayLogger();
33
    }
34
35
    /**
36
     * tearDown
37
     *
38
     * @return void
39
     */
40
    protected function tearDown(): void
41
    {
42
        parent::tearDown();
43
    }
44
45
    /**
46
     * Invokes a inaccessible method.
47
     *
48
     * @param $object
49
     * @param $method
50
     * @param array $args
51
     * @param bool $revoke whether to make method inaccessible after execution
52
     *
53
     * @return mixed
54
     */
55
    protected function invokeMethod($object, $method, $args = [], $revoke = true)
56
    {
57
        $reflection = new \ReflectionObject($object);
58
        $method = $reflection->getMethod($method);
59
        $method->setAccessible(true);
60
        $result = $method->invokeArgs($object, $args);
61
62
        if ($revoke) {
63
            $method->setAccessible(false);
64
        }
65
66
        return $result;
67
    }
68
}
69