Yii 的简单数据库单元测试中出现的这个错误是什么?
root@u1010:/opt/lampp/htdocs/trackstar/protected/tests# phpunit unit/DbTest.php
PHPUnit 3.4.13 by Sebastian Bergmann.
E
Time: 2 seconds, Memory: 5.75Mb
There was 1 error:
1) DbTest::testConnection
CDbException: CDbConnection failed to open the DB connection.
/opt/lampp/htdocs/yii/framework/db/CDbConnection.php:275
/opt/lampp/htdocs/yii/framework/db/CDbConnection.php:242
/opt/lampp/htdocs/yii/framework/db/CDbConnection.php:221
/opt/lampp/htdocs/yii/framework/base/CModule.php:363
/opt/lampp/htdocs/yii/framework/base/CModule.php:86
/opt/lampp/htdocs/trackstar/protected/tests/unit/DbTest.php:6
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
root@u1010:/opt/lampp/htdocs/trackstar/protected/tests#
root@u1010:/opt/lampp/htdocs/trackstar/protected/tests# phpunit unit/DbTest.php
PHPUnit 3.4.13 by Sebastian Bergmann.
E
Time: 2 seconds, Memory: 5.75Mb
There was 1 error:
1) DbTest::testConnection
CDbException: CDbConnection failed to open the DB connection.
/opt/lampp/htdocs/yii/framework/db/CDbConnection.php:275
/opt/lampp/htdocs/yii/framework/db/CDbConnection.php:242
/opt/lampp/htdocs/yii/framework/db/CDbConnection.php:221
/opt/lampp/htdocs/yii/framework/base/CModule.php:363
/opt/lampp/htdocs/yii/framework/base/CModule.php:86
/opt/lampp/htdocs/trackstar/protected/tests/unit/DbTest.php:6
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
root@u1010:/opt/lampp/htdocs/trackstar/protected/tests#
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该在 protected/config/test.php 中编辑“db”组件声明
。运行测试时将使用此配置文件。
检查 protected/tests/bootstrap.php 以查看包含的文件。
You should edit the 'db' component declaration in protected/config/test.php
This configuration file is used when you're running your tests.
Check protected/tests/bootstrap.php to see the included files.
好的。拔掉头发大约半天后。这就是我所要做的。希望它对其他人有帮助。几个简单的检查解决了这个问题。我有 php 和 phpunit 的多个副本,具有不同的路径。我假设您已通过 /requirements/index.php 检查,并且您的 config/main &测试文件集。
在终端中找到您的 PHPUnit 可执行文件:
which phpunit
找到您正在运行的 php 可执行文件:
which php
sudo vi path/to/phpunit (可执行文件)
make确保引用 php 可执行文件的第一行实际上是第二步中的行。
解决了我的头痛。 :)
Okay. After about half a day of pulling my hair out. This is all I had to do. Hope it helps others. Several simple checks solved this issue. I've got multiple copies of both php and phpunit with different paths. I'm assuming you have your /requirements/index.php checks passed, and your config/main & test files set.
In terminal locate your PHPUnit executable:
which phpunit
Locate your running php executable:
which php
sudo vi path/to/phpunit (the executable)
make sure that the first line referencing the php exectuable is actually the one from step two.
Solved my headache. :)
它无法连接到您的数据库。要么:
It could not connect to your database. Either:
尝试:
有时MySQL服务器的权限设置对于“127.0.0.1”和“localhost”是不同的。如果是这种情况,你可以这样做:
在你的 mysql 服务器上
try:
sometimes the privileges setting for the MySQL server are different for "127.0.0.1" and "localhost". If this is the case, you can do:
on your mysql server