|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* trait for test functions |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\TestBundle\Test; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
10
|
|
|
* @license https://opensource.org/licenses/MIT MIT License |
|
11
|
|
|
* @link http://swisscom.ch |
|
12
|
|
|
*/ |
|
13
|
|
|
trait PrivateClassMethodTrait |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Testing private methods for a class. |
|
18
|
|
|
* |
|
19
|
|
|
* $class = new YourClass(); or service... |
|
20
|
|
|
* $method = $this->getPrivateClassMethod(get_class($class), 'getPrivateFunction'); |
|
21
|
|
|
* $result = $method->invokeArgs( $this->activityManager, [argument1, argument2, ...]); |
|
22
|
|
|
* |
|
23
|
|
|
* @param string $className String name for class, full namespace. |
|
24
|
|
|
* @param string $methodName Method name to be used |
|
25
|
|
|
* |
|
26
|
|
|
* @return \ReflectionMethod |
|
27
|
|
|
* @throws \ReflectionException |
|
28
|
|
|
*/ |
|
29
|
20 |
|
public function getPrivateClassMethod($className, $methodName) |
|
30
|
|
|
{ |
|
31
|
20 |
|
$reflector = new \ReflectionClass($className); |
|
32
|
20 |
|
$method = $reflector->getMethod($methodName); |
|
33
|
20 |
|
$method->setAccessible(true); |
|
34
|
20 |
|
return $method; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* provide a protected property of a given object. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $className String name for class, full namespace. |
|
41
|
|
|
* @param string $propertyName property name |
|
42
|
|
|
* |
|
43
|
|
|
* @return \ReflectionProperty |
|
44
|
|
|
* @throws \ReflectionException |
|
45
|
|
|
*/ |
|
46
|
4 |
|
public function getPrivateClassProperty($className, $propertyName) |
|
47
|
|
|
{ |
|
48
|
4 |
|
$reflector = new \ReflectionClass($className); |
|
49
|
4 |
|
$prop = $reflector->getProperty($propertyName); |
|
50
|
4 |
|
$prop->setAccessible(true); |
|
51
|
4 |
|
return $prop; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|