Completed
Branch master (51b807)
by Frank
04:17 queued 02:02
created

BaseTestCase   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1
1
<?php
2
/**
3
 * T3Bot.
4
 *
5
 * @author Frank Nägler <[email protected]>
6
 *
7
 * @link http://www.t3bot.de
8
 * @link http://wiki.typo3.org/T3Bot
9
 */
10
namespace T3Bot\Tests\Unit;
11
12
use MyProject\Proxies\__CG__\stdClass;
13
14
/**
15
 * Class BaseTestCase.
16
 */
17
class BaseTestCase extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * Call protected/private method of a class.
21
     *
22
     * @param mixed  &$object    Instantiated object that we will run method on.
23
     * @param string $methodName Method name to call
24
     * @param array  $parameters Array of parameters to pass into method.
25
     *
26
     * @return mixed Method return.
27
     */
28
    public function invokeMethod(&$object, $methodName, array $parameters = [])
29
    {
30
        $reflection = new \ReflectionClass(get_class($object));
31
        $method = $reflection->getMethod($methodName);
32
        $method->setAccessible(true);
33
34
        return $method->invokeArgs($object, $parameters);
35
    }
36
37
    /**
38
     * @param stdClass $object
39
     * @param string   $property
40
     * @param mixed    $value
41
     */
42
    public function setProperty(&$object, $property, $value)
43
    {
44
        $reflection = new \ReflectionClass(get_class($object));
45
        $_property = $reflection->getProperty($property);
46
        $_property->setAccessible(true);
47
        $object->$property = $value;
48
    }
49
}
50