Last active
April 1, 2020 02:00
-
-
Save RickySu/3a6849629dd7d299f6583f77d1818f6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
trait TestCaseTrait | |
{ | |
protected function callObjectMethod($object, $methodName) | |
{ | |
$args = func_get_args(); | |
array_shift($args); //$object | |
array_shift($args); //$methodName | |
$reflect = new \ReflectionClass($object); | |
$method = $reflect->getMethod($methodName); | |
$method->setAccessible(true); | |
return $method->invokeArgs($object, $args); | |
} | |
protected function setObjectAttribute($object, $attributeName, $value, $class = null) | |
{ | |
$reflect = new \ReflectionClass($class === null ? $object : $class); | |
$property = $reflect->getProperty($attributeName); | |
$property->setAccessible(true); | |
$property->setValue($object, $value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment