PHPUnit RabbitMQ:编写用于创建连接功能的测试

迪克万

我正面临以下问题。我编写了一个函数,该函数根据给定的参数创建连接对象(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);
        }
    }
}
Chozilla

通常,您不会像这样将代码作为单元测试进行测试,因为结果很可能会告诉您服务器已正确安装,而不是代码正在运行。

您是否测试PDO是否返回有效的数据库连接?

如果您测试安装,但不测试php c库是否正常工作,这可能很有意义。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章