mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
77 lines
1.9 KiB
PHP
77 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Orange Management
|
|
*
|
|
* PHP Version 7.1
|
|
*
|
|
* @category TBD
|
|
* @package TBD
|
|
* @author OMS Development Team <dev@oms.com>
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 1.0
|
|
* @version 1.0.0
|
|
* @link http://orange-management.com
|
|
*/
|
|
declare(strict_types=1);
|
|
namespace phpOMS\Utils;
|
|
/**
|
|
* Test utils.
|
|
*
|
|
* Only for testing purposes. MUST NOT be used for other purposes.
|
|
*
|
|
* @category Framework
|
|
* @package phpOMS\Utils
|
|
* @author OMS Development Team <dev@oms.com>
|
|
* @license OMS License 1.0
|
|
* @link http://orange-management.com
|
|
* @since 1.0.0
|
|
*/
|
|
class TestUtils
|
|
{
|
|
public static function setMember($obj, $name, $value) : bool
|
|
{
|
|
$reflectionClass = new \ReflectionClass(get_class($obj));
|
|
|
|
if(!$reflectionClass->hasProperty($name)) {
|
|
return false;
|
|
}
|
|
|
|
$reflectionProperty = $reflectionClass->getProperty($name);
|
|
|
|
if (!($accessible = $reflectionProperty->isPublic())) {
|
|
$reflectionProperty->setAccessible(true);
|
|
}
|
|
|
|
$reflectionProperty->setValue($obj, $value);
|
|
|
|
if (!$accessible) {
|
|
$reflectionProperty->setAccessible(false);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static function getMember($obj, $name)
|
|
{
|
|
$reflectionClass = new \ReflectionClass(get_class($obj));
|
|
|
|
if(!$reflectionClass->hasProperty($name)) {
|
|
return null;
|
|
}
|
|
|
|
$reflectionProperty = $reflectionClass->getProperty($name);
|
|
|
|
if (!($accessible = $reflectionProperty->isPublic())) {
|
|
$reflectionProperty->setAccessible(true);
|
|
}
|
|
|
|
$value = $reflectionProperty->getValue($obj);
|
|
|
|
if (!$accessible) {
|
|
$reflectionProperty->setAccessible(false);
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
}
|