微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – max连接MySql在测试期间到达

当我启动我的 PHPUnit测试套件时,我达到MysqL的最大连接限制(200).

热修复是将max_connection设置为500,但是我在Zend Framework 2上下文中寻找更好的解决方案.

我试图放一些tearDown方法,但没有运气似乎是无用的或不完整的解决方案.

这是一个代码示例:

protected function tearDown()
{
    // i have two entitymanager
    $this->getobjectManager()->get('doctrine.connection.orm_alternate')->close();
    $this->getobjectManager()->get('doctrine.connection.orm_default')->close();
    $this->application = null;
    gc_collect_cycles();
    parent::tearDown();
}

我也试图使用processIsolation转为true,但一些测试是如此之长,以至于我假设我的控制台已经冻结或类似的东西….

使用doctrine2连接和Zend Framework,如何在PHPunit测试期间阻止这种“太多连接”?

到目前为止,我尝试修改了@awons的提示
$这个 – > getobjectManager() – >获得( ‘doctrine.connection.orm_alternate’) – >关闭();


$这个 – > getobjectManager() – >获得( ‘doctrine.entitymanager.orm_alternate’) – >关闭();

是的,我检查了是否拆卸.

我不明白的是:在每个测试中,我的连接的一个新实例被创建,为什么这不是一样的实例? (像单身或注册)?
但是,即使测试通过后,该实例也不会关闭.

我错了,但不知道什么.

在这样做之前,我已经解决了类似的问题:
protected static $my_db_for_testing

public static function setUpBeforeClass()
{
    //create your DB connection once,here.
    $self::$my_db_for_testing = new DbConnectionWhatever()
}

protected function setUp()
{
    $this->my_obj_to_test = new MyObject();
    $this->my_obj_to_test->setDb($this->my_db_for_testing);
}



public function testOne()
{
    //normal test here
}

public static function tearDownAfterClass()
{
    //close the DB connection here
}

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐