Просмотр исходного кода

#5690 Unit tests: remove deprecated code

Aleksandr Trofimov 1 месяц назад
Родитель
Сommit
ccf781ecaa
2 измененных файлов с 10 добавлено и 18 удалено
  1. 6 6
      tests/bootstrap.php
  2. 4 12
      tests/units/modules/boonex/persons/BxPersonsTestCase.php

+ 6 - 6
tests/bootstrap.php

@@ -107,28 +107,28 @@ class BxDolTestCase extends \PHPUnit\Framework\TestCase
     protected function bxCallProtected($o, $sMethod, ...$aArgs)
     {
         $oMethod = new ReflectionMethod($o, $sMethod);
-        $oMethod->setAccessible(true);
         return $oMethod->invokeArgs($o, $aArgs);
     }
 
     protected function bxCallProtectedArgs($o, $sMethod, array $aArgs)
     {
         $oMethod = new ReflectionMethod($o, $sMethod);
-        $oMethod->setAccessible(true);
         return $oMethod->invokeArgs($o, $aArgs);
     }
 
+    protected function bxGetProtected($o, $sProperty, $sClass = null)
+    {
+        return (new ReflectionProperty($sClass ?: $o, $sProperty))->getValue($o);
+    }
+
     protected function bxSetProtected($o, $sProperty, $mixedValue, $sClass = null)
     {
-        $oProperty = new ReflectionProperty($sClass ?: $o, $sProperty);
-        $oProperty->setAccessible(true);
-        $oProperty->setValue($o, $mixedValue);
+        (new ReflectionProperty($sClass ?: $o, $sProperty))->setValue($o, $mixedValue);
     }
 
     protected function bxModuleInstances(BxDolModule $oModule, ?array $aReplace = null): array
     {
         $oProperty = new ReflectionProperty(BxDolModule::class, '_aInstancesStorage');
-        $oProperty->setAccessible(true);
         $aCurrent = $oProperty->getValue($oModule) ?: [];
         if ($aReplace !== null)
             $oProperty->setValue($oModule, $aReplace);

+ 4 - 12
tests/units/modules/boonex/persons/BxPersonsTestCase.php

@@ -19,23 +19,15 @@ abstract class BxPersonsTestCase extends BxDolTestCase
         foreach (['SearchResult', 'FormEntry', 'FormsEntryHelper'] as $sClass)
             bx_import($sClass, $this->_oModule->_aModule);
 
-        $oProfileId = new ReflectionProperty(BxBaseModGeneralModule::class, '_iProfileId');
-        $oProfileId->setAccessible(true);
-        $this->_iProfileIdBackup = $oProfileId->getValue($this->_oModule);
-
-        $oAccountId = new ReflectionProperty(BxBaseModProfileModule::class, '_iAccountId');
-        $oAccountId->setAccessible(true);
-        $this->_iAccountIdBackup = $oAccountId->getValue($this->_oModule);
+        $this->_iProfileIdBackup = $this->bxGetProtected($this->_oModule, '_iProfileId', BxBaseModGeneralModule::class);
+        $this->_iAccountIdBackup = $this->bxGetProtected($this->_oModule, '_iAccountId', BxBaseModProfileModule::class);
     }
 
     protected function bxTemplate()
     {
         $oTemplate = $this->_oModule->_oTemplate;
-        if ($oTemplate instanceof BxDolModuleProxy) {
-            $oProperty = new ReflectionProperty(BxDolModuleProxy::class, '_oProxifiedObject');
-            $oProperty->setAccessible(true);
-            $oTemplate = $oProperty->getValue($oTemplate);
-        }
+        if ($oTemplate instanceof BxDolModuleProxy)
+            $oTemplate = $this->bxGetProtected($oTemplate, '_oProxifiedObject', BxDolModuleProxy::class);
 
         return $oTemplate;
     }