Completed
Pull Request — master (#13)
by Lhalaa
01:17
created

TestHelper   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A invokeMethod() 0 8 1
1
<?php
2
3
namespace Firesphere\PartialUserforms\Tests;
4
5
/**
6
 * A simple helper class for tests
7
 * @package Firesphere\PartialUserforms\Tests
8
 */
9
class TestHelper
10
{
11
    /**
12
     * Call protected/private method of a class
13
     *
14
     * @param Object $object
15
     * @param string $methodName
16
     * @param array $parameters
17
     * @return mixed
18
     * @throws \ReflectionException
19
     *
20
     * @link https://jtreminio.com/blog/unit-testing-tutorial-part-iii-testing-protected-private-methods-coverage-reports-and-crap/
21
     */
22
    public static function invokeMethod(&$object, $methodName, array $parameters = array())
23
    {
24
        $reflection = new \ReflectionClass(get_class($object));
25
        $method = $reflection->getMethod($methodName);
26
        $method->setAccessible(true);
27
28
        return $method->invokeArgs($object, $parameters);
29
    }
30
}
31