【发布时间】:2015-05-20 08:11:19
【问题描述】:
我面临以下问题。我编写了一个函数,它在给定所需参数的情况下创建连接对象 (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);
}
}
}
【问题讨论】: