mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-20 17:18:51 +02:00
N°4215 Fix call to a function on null error when setting TLS connection in the setup
Regression introduced by b1ca1f2630 / N°3513
This commit is contained in:
@@ -154,6 +154,12 @@ class CMDBSource
|
||||
|
||||
/** @var mysqli $m_oMysqli */
|
||||
protected static $m_oMysqli;
|
||||
/**
|
||||
* @var mysqli $oMySQLiForQuery
|
||||
* @see GetMySQLiForQuery
|
||||
* @see SetMySQLiForQuery
|
||||
* @since 2.7.5 N°3513 new var to allow mock in tests ({@see \Combodo\iTop\Test\UnitTest\Core\TransactionsTest})
|
||||
*/
|
||||
protected static $oMySQLiForQuery;
|
||||
|
||||
/**
|
||||
@@ -348,9 +354,9 @@ class CMDBSource
|
||||
*/
|
||||
private static function IsOpenedDbConnectionUsingTls($oMysqli)
|
||||
{
|
||||
if (self::$m_oMysqli == null)
|
||||
if (is_null(self::GetMySQLiForQuery()))
|
||||
{
|
||||
self::$m_oMysqli = $oMysqli;
|
||||
self::SetMySQLiForQuery($oMysqli);
|
||||
}
|
||||
|
||||
$bNonEmptySslVersionVar = self::IsMySqlVarNonEmpty('ssl_version');
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use CMDBSource;
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* @since 2.7.0
|
||||
@@ -115,4 +116,23 @@ class CMDBSourceTest extends ItopTestCase
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \ConfigException
|
||||
* @throws \CoreException
|
||||
* @throws \MySQLException
|
||||
* @since 3.0.0 N°4215
|
||||
*/
|
||||
public function testIsOpenedDbConnectionUsingTls() {
|
||||
$oConfig = utils::GetConfig();
|
||||
CMDBSource::InitFromConfig($oConfig);
|
||||
$oMysqli = CMDBSource::GetMysqli();
|
||||
|
||||
// resets \CMDBSource::$oMySQLiForQuery to simulate call to \CMDBSource::Init with a LTS connexion
|
||||
$this->InvokeNonPublicStaticMethod(CMDBSource::class, 'SetMySQLiForQuery',[null]);
|
||||
|
||||
// before N°4215 fix, this was crashing : "Call to a member function query() on null"
|
||||
$bIsTlsCnx = $this->InvokeNonPublicStaticMethod(CMDBSource::class, 'IsOpenedDbConnectionUsingTls',[$oMysqli]);
|
||||
$this->assertFalse($bIsTlsCnx);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user