fix unit test

This commit is contained in:
Chirag Aggarwal 2026-02-04 14:30:24 +05:30
parent 4b02bf1aa8
commit 579f07f8bb

View file

@ -39,12 +39,21 @@ class Realtime extends MessagingAdapter
*/
public array $subscriptions = [];
private PubSubPool $pubSubPool;
private ?PubSubPool $pubSubPool = null;
public function __construct()
/**
* Get the PubSubPool instance, initializing it lazily if needed.
* This allows unit tests to work without requiring the global $register.
*
* @return PubSubPool
*/
private function getPubSubPool(): PubSubPool
{
global $register;
$this->pubSubPool = new PubSubPool($register->get('pools')->get('pubsub'));
if ($this->pubSubPool === null) {
global $register;
$this->pubSubPool = new PubSubPool($register->get('pools')->get('pubsub'));
}
return $this->pubSubPool;
}
/**
@ -224,7 +233,7 @@ class Realtime extends MessagingAdapter
$permissionsChanged = array_key_exists('permissionsChanged', $options) && $options['permissionsChanged'];
$userId = array_key_exists('userId', $options) ? $options['userId'] : null;
$this->pubSubPool->publish('realtime', json_encode([
$this->getPubSubPool()->publish('realtime', json_encode([
'project' => $projectId,
'roles' => $roles,
'permissionsChanged' => $permissionsChanged,