加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHPUnit RabbitMQ:为create connection函数编写测试

发布时间:2020-12-13 16:56:38 所属栏目:PHP教程 来源:网络整理
导读:我面临以下问题.我编写了一个函数,在给定所需参数的情况下创建连接对象(AMQPConnection).现在我想写相应的单元测试.我不知道如何在没有运行RabbitMQ代理的情况下做到这一点.这是有问题的功能: public function getConnection($hostKey,array $params){ $con
我面临以下问题.我编写了一个函数,在给定所需参数的情况下创建连接对象(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);
        }
    }
}

解决方法

您通常不会将此类代码作为Unittest进行测试,因为结果更可能会告诉您服务器安装正确而不是代码正常工作.

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

如果你测试你的安装但不测试php c libs是否正常工作可能是有意义的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读