小编dic*_*wan的帖子

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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

php phpunit rabbitmq

5
推荐指数
1
解决办法
3323
查看次数

标签 统计

php ×1

phpunit ×1

rabbitmq ×1