mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 15:34:12 +01:00
Merge remote-tracking branch 'origin/support/3.0' into support/3.1
# Conflicts: # tests/php-unit-tests/integration-tests/DictionariesConsistencyTest.php # tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php # tests/php-unit-tests/unitary-tests/core/CMDBSource/TransactionsTest.php # tests/php-unit-tests/unitary-tests/sources/Application/TwigBase/Twig/TwigTest.php
This commit is contained in:
@@ -13,6 +13,8 @@ use SetupUtils;
|
||||
use const DEBUG_BACKTRACE_IGNORE_ARGS;
|
||||
|
||||
/**
|
||||
* Class ItopTestCase
|
||||
*
|
||||
* Helper class to extend for tests that DO NOT need to access the DataModel or the Database
|
||||
*
|
||||
* @since 3.0.4 3.1.1 3.2.0 N°6658 move some setUp/tearDown code to the corresponding methods *BeforeClass to speed up tests process time.
|
||||
@@ -21,6 +23,7 @@ abstract class ItopTestCase extends TestCase
|
||||
{
|
||||
public const TEST_LOG_DIR = 'test';
|
||||
public static $DEBUG_UNIT_TEST = false;
|
||||
protected static $aBackupStaticProperties = [];
|
||||
|
||||
/**
|
||||
* @link https://docs.phpunit.de/en/9.6/annotations.html#preserveglobalstate PHPUnit `preserveGlobalState` annotation documentation
|
||||
@@ -302,6 +305,42 @@ abstract class ItopTestCase extends TestCase
|
||||
return $oProperty->getValue($oObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Backup every static property of the class (even protected ones)
|
||||
* @param string $sClass
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function BackupStaticProperties($sClass)
|
||||
{
|
||||
$class = new \ReflectionClass($sClass);
|
||||
foreach ($class->getProperties() as $property) {
|
||||
if (!$property->isStatic()) continue;
|
||||
$property->setAccessible(true);
|
||||
static::$aBackupStaticProperties[$sClass][$property->getName()] = $property->getValue();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore every static property of the class (even protected ones)
|
||||
* @param string $sClass
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function RestoreStaticProperties($sClass)
|
||||
{
|
||||
$class = new \ReflectionClass($sClass);
|
||||
foreach ($class->getProperties() as $property) {
|
||||
if (!$property->isStatic()) continue;
|
||||
$property->setAccessible(true);
|
||||
$property->setValue(static::$aBackupStaticProperties[$sClass][$property->getName()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.7.10 3.1.0
|
||||
*/
|
||||
@@ -337,14 +376,14 @@ abstract class ItopTestCase extends TestCase
|
||||
$oProperty->setValue($value);
|
||||
}
|
||||
|
||||
public function RecurseRmdir($dir)
|
||||
public static function RecurseRmdir($dir)
|
||||
{
|
||||
if (is_dir($dir)) {
|
||||
$objects = scandir($dir);
|
||||
foreach ($objects as $object) {
|
||||
if ($object != "." && $object != "..") {
|
||||
if (is_dir($dir.DIRECTORY_SEPARATOR.$object)) {
|
||||
$this->RecurseRmdir($dir.DIRECTORY_SEPARATOR.$object);
|
||||
static::RecurseRmdir($dir.DIRECTORY_SEPARATOR.$object);
|
||||
} else {
|
||||
unlink($dir.DIRECTORY_SEPARATOR.$object);
|
||||
}
|
||||
@@ -354,7 +393,7 @@ abstract class ItopTestCase extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function CreateTmpdir() {
|
||||
public static function CreateTmpdir() {
|
||||
$sTmpDir=tempnam(sys_get_temp_dir(),'');
|
||||
if (file_exists($sTmpDir))
|
||||
{
|
||||
@@ -369,7 +408,7 @@ abstract class ItopTestCase extends TestCase
|
||||
return sys_get_temp_dir();
|
||||
}
|
||||
|
||||
public function RecurseMkdir($sDir){
|
||||
public static function RecurseMkdir($sDir){
|
||||
if (strpos($sDir, DIRECTORY_SEPARATOR) === 0){
|
||||
$sPath = DIRECTORY_SEPARATOR;
|
||||
} else {
|
||||
@@ -394,13 +433,13 @@ abstract class ItopTestCase extends TestCase
|
||||
|
||||
}
|
||||
|
||||
public function RecurseCopy($src,$dst) {
|
||||
public static function RecurseCopy($src,$dst) {
|
||||
$dir = opendir($src);
|
||||
@mkdir($dst);
|
||||
while(false !== ( $file = readdir($dir)) ) {
|
||||
if (( $file != '.' ) && ( $file != '..' )) {
|
||||
if ( is_dir($src . '/' . $file) ) {
|
||||
$this->RecurseCopy($src . DIRECTORY_SEPARATOR . $file,$dst . DIRECTORY_SEPARATOR . $file);
|
||||
static::RecurseCopy($src . DIRECTORY_SEPARATOR . $file,$dst . DIRECTORY_SEPARATOR . $file);
|
||||
}
|
||||
else {
|
||||
copy($src . DIRECTORY_SEPARATOR . $file,$dst . DIRECTORY_SEPARATOR . $file);
|
||||
|
||||
Reference in New Issue
Block a user