From 765560d1f58b86ca8fa02ff09c9739c0ed2dbf6b Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Tue, 2 Feb 2021 17:57:40 +0100 Subject: [PATCH] ItopTestCase : helpers to call invisble methods --- test/ItopTestCase.php | 24 +++++++++++++++++++ test/core/DBSearchUpdateRealiasingMapTest.php | 12 +++------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/test/ItopTestCase.php b/test/ItopTestCase.php index 82adec874..6dc33b279 100644 --- a/test/ItopTestCase.php +++ b/test/ItopTestCase.php @@ -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); + } } \ No newline at end of file diff --git a/test/core/DBSearchUpdateRealiasingMapTest.php b/test/core/DBSearchUpdateRealiasingMapTest.php index ece5dd312..8d363869c 100644 --- a/test/core/DBSearchUpdateRealiasingMapTest.php +++ b/test/core/DBSearchUpdateRealiasingMapTest.php @@ -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]); - } }