File tree 1 file changed +22
-4
lines changed
1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change 4
4
5
5
namespace Php \Support \Testing ;
6
6
7
- use function instance ;
7
+ use ReflectionClass ;
8
8
9
9
trait TestingHelper
10
10
{
@@ -21,12 +21,30 @@ trait TestingHelper
21
21
* @example
22
22
* $result = $this->runProtectedMethod($sp, "registerService", T::class);
23
23
*/
24
- public function runProtectedMethod (string |object $ class , string $ method , ...$ params ): mixed
24
+ protected function runProtectedMethod (string |object $ class , string $ method , ...$ params ): mixed
25
25
{
26
- $ class = instance ($ class );
27
-
28
26
$ methodReflex = new \ReflectionMethod ($ class , $ method );
29
27
$ methodReflex ->setAccessible (true );
30
28
return $ methodReflex ->invoke ($ class , ...$ params );
31
29
}
30
+
31
+ /**
32
+ * Get a instance property (public/private/protected) value.
33
+ *
34
+ * @param object|string $object
35
+ * @param string $property_name
36
+ *
37
+ * @return mixed
38
+ * @throws \ReflectionException
39
+ *
40
+ */
41
+ protected function getProperty (object |string $ object , string $ propertyName ): mixed
42
+ {
43
+ $ reflection = new ReflectionClass ($ object );
44
+
45
+ $ property = $ reflection ->getProperty ($ propertyName );
46
+ $ property ->setAccessible (true );
47
+
48
+ return $ property ->getValue ($ object );
49
+ }
32
50
}
You can’t perform that action at this time.
0 commit comments