Skip to content

Instantly share code, notes, and snippets.

@RickySu
Last active April 1, 2020 02:00
Show Gist options
  • Save RickySu/3a6849629dd7d299f6583f77d1818f6e to your computer and use it in GitHub Desktop.
Save RickySu/3a6849629dd7d299f6583f77d1818f6e to your computer and use it in GitHub Desktop.
<?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