我面临以下问题。我编写了一个函数,根据所需参数创建连接对象 (AMQPConnection)。现在我想编写相应的单元测试。我只是不知道在没有运行 RabbitMQ 代理的情况下如何做到这一点。这是有问题的函数:
public function getConnection($hostKey, array $params)
{
$connection = null;
try {
$connection = new AMQPConnection(
$params['host'],
$params['port'],
$params['username'],
$params['password'],
$params['vhost']
);
// set this server as default for next connection connectionAttempt
$this->setDefaultHostConfig($hostKey, $params);
return $connection;
} catch (\Exception $ex) {
if ($this->isAttemptExceeded()) {
return $connection;
} else {
// increment connection connectionAttempt
$this->setConnectionAttempt($this->getConnectionAttempt() + 1);
return $this->getConnection($hostKey, $params);
}
}
}
Run Code Online (Sandbox Code Playgroud)