Skip to content

Commit e26c104

Browse files
authored
Update BaseTestCase.php
1 parent 8c0384f commit e26c104

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/BaseTestCase.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,35 @@
1212
abstract class BaseTestCase extends TestCase
1313
{
1414

15+
/**
16+
* get method for test protected and private method
17+
*
18+
* usage:
19+
*
20+
* ```php
21+
* $rftMth = $this->method($className, $protectedOrPrivateMethod)
22+
*
23+
* $obj = new $className();
24+
* $res = $rftMth->invokeArgs($obj, $invokeArgs);
25+
* ```
26+
*
27+
* @param string|object $class
28+
* @param string $method
29+
*
30+
* @return ReflectionMethod
31+
* @throws ReflectionException
32+
*/
33+
protected static function getMethod($class, string $method): ReflectionMethod
34+
{
35+
// $class = new \ReflectionClass($class);
36+
// $method = $class->getMethod($method);
37+
38+
$method = new \ReflectionMethod($class, $method);
39+
$method->setAccessible(true);
40+
41+
return $method;
42+
}
43+
1544
/**
1645
* @param callable $cb
1746
*

0 commit comments

Comments
 (0)