我们有大约 180 个单元测试工具 webtestcase
类和测试正在 Controller 上运行。
但是,当我们运行单元测试时,它们打开了太多与 db 的连接。由于过多的事件 tcp 连接测试在第 120 次测试后失败。测试运行时,所有连接都处于事件状态。
在tearDown函数中我们调用了entity manager的close函数,但是什么都没有,没有任何影响。我认为有一些类保持连接对象引用。
因为在 php 手册中提到了当对象分配为 null 时 pdo 连接关闭。我们也这样做,但没有改变。
P.S:我们的单元测试是功能测试。在 Controller 上工作并与数据库集成,没有模拟对象
我们的错误在哪里?我们如何解决问题?
这是我在 config_test.yml 中的连接参数
imports:
- { resource: config_dev.yml }
framework:
test: ~
session:
storage_id: session.storage.mock_file
web_profiler:
toolbar: false
intercept_redirects: false
doctrine:
dbal:
driver: pdo_mysql
port: 3306
host: localhost
dbname: mydb
user: myuser
password: mypass
charset: UTF8
最佳答案
你检查过你的 phpunit.xml.dist 文件了吗?
我认为你应该看看这个;
http://www.slideshare.net/fabpot/unit-and-functional-testing-with-symfony2
确保您的参数在下面相同
<phpunit
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "true"
stopOnFailure = "false"
syntaxCheck = "false"
bootstrap = "bootstrap.php.cache" >
关于symfony - 当 phpunit 与 symfony 2.X 一起运行时,PDO 连接未关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16892355/