当我启动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 测试期间如何防止 "Too many connection"?
迄今为止,根据 @awons 的提示,我尝试修改
$this->getObjectManager()->get('doctrine.connection.orm_alternate')->close();
改为
$this->getObjectManager()->get('doctrine.entitymanager.orm_alternate')->close();
我检查了 teardown 是否被调用过,是的。
有些我不明白的是:每次测试都会创建一个连接的新实例,为什么这不是同一个实例?(像单例或注册表)?但即使在测试通过后没有使用它,这个实例也永远不会关闭。
我错过了什么但不知道是什么。
$this->getObjectManager()->close()
? - Aleksander Wons$this->getObjectManager()->get('doctrine')
这样的代码? - Aleksander Wons