mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
ItopTestCase : helpers to call invisble methods
This commit is contained in:
@@ -93,7 +93,31 @@ class ItopTestCase extends TestCase
|
||||
{
|
||||
$sId = str_replace('"', '', $this->getName());
|
||||
$sId = str_replace(' ', '_', $sId);
|
||||
|
||||
return $sId;
|
||||
}
|
||||
|
||||
public function InvokeInvisibleStaticMethod($sObjectClass, $sMethodName, $aArgs)
|
||||
{
|
||||
return $this->InvokeInvisibleMethod($sObjectClass, $sMethodName, null, $aArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sObjectClass for example DBObject::class
|
||||
* @param string $sMethodName
|
||||
* @param object $oObject
|
||||
* @param array $aArgs
|
||||
*
|
||||
* @return mixed method result
|
||||
*
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function InvokeInvisibleMethod($sObjectClass, $sMethodName, $oObject, $aArgs)
|
||||
{
|
||||
$class = new \ReflectionClass($sObjectClass);
|
||||
$method = $class->getMethod($sMethodName);
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method->invokeArgs($oObject, $aArgs);
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,9 @@ class DBSearchUpdateRealiasingMapTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testUpdateRealiasingMap($aRealiasingMap, $aAliasTranslation, $aExpectedRealiasingMap)
|
||||
{
|
||||
$this->UpdateRealiasingMap($aRealiasingMap, $aAliasTranslation);
|
||||
$oObject = new DBObjectSearch('Organization');
|
||||
$aArgs = [&$aRealiasingMap, $aAliasTranslation];
|
||||
$this->InvokeInvisibleMethod(DBObjectSearch::class, 'UpdateRealiasingMap', $oObject, $aArgs);
|
||||
$this->assertEquals($aExpectedRealiasingMap, $aRealiasingMap);
|
||||
}
|
||||
|
||||
@@ -77,12 +79,4 @@ class DBSearchUpdateRealiasingMapTest extends ItopDataTestCase
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private function UpdateRealiasingMap(&$aRealiasingMap, $aAliasTranslation)
|
||||
{
|
||||
$class = new \ReflectionClass(DBObjectSearch::class);
|
||||
$method = $class->getMethod('UpdateRealiasingMap');
|
||||
$method->setAccessible(true);
|
||||
$method->invokeArgs(new DBObjectSearch('Organization'), [&$aRealiasingMap, $aAliasTranslation]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user