N°4756 - Fix Unit tests

This commit is contained in:
Eric Espie
2022-11-18 10:49:59 +01:00
parent 6585f717c5
commit 52c984d5e7
4 changed files with 32 additions and 14 deletions

View File

@@ -16,9 +16,9 @@ use utils;
class EventService
{
public static $aEventListeners;
private static $iEventIdCounter;
private static $aEventDescription;
public static $aEventListeners = [];
private static $iEventIdCounter = 0;
private static $aEventDescription = [];
public static function InitService()
{
@@ -103,7 +103,7 @@ class EventService
public static function FireEvent(EventData $oEventData)
{
$sEvent = $oEventData->GetEvent();
if (!array_key_exists($sEvent, self::$aEventDescription)) {
if (!self::IsEventRegistered($sEvent)) {
$sError = "Fire event error: Event $sEvent is not registered";
EventHelper::Error($sError);
throw new CoreException($sError);
@@ -267,9 +267,10 @@ class EventService
*/
public static function RegisterEvent(string $sEvent, array $aDescription, string $sModule)
{
if (isset(self::$aEventDescription[$sEvent])) {
if (self::IsEventRegistered($sEvent)) {
$sPrevious = self::$aEventDescription[$sEvent]['module'];
EventHelper::Error("The Event $sEvent defined by $sModule has already been defined in $sPrevious, check your delta");
EventHelper::Warning("The Event $sEvent defined by $sModule has already been defined in $sPrevious, check your delta");
return;
}
self::$aEventDescription[$sEvent] = [
@@ -309,6 +310,16 @@ class EventService
return implode('_', $aRet);
}
/**
* @param string $sEvent
*
* @return bool
*/
public static function IsEventRegistered(string $sEvent): bool
{
return array_key_exists($sEvent, self::$aEventDescription);
}
public static function GetDefinedEventsAsJSON()
{
return json_encode(self::$aEventDescription, JSON_PRETTY_PRINT);