Yii 的简单数据库单元测试中出现的这个错误是什么?

发布于 2024-10-02 09:44:05 字数 730 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

好多鱼好多余 2024-10-09 09:44:05

您应该在 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.

放低过去 2024-10-09 09:44:05

好的。拔掉头发大约半天后。这就是我所要做的。希望它对其他人有帮助。几个简单的检查解决了这个问题。我有 php 和 phpunit 的多个副本,具有不同的路径。我假设您已通过 /requirements/index.php 检查,并且您的 config/main &测试文件集。

  1. 在终端中找到您的 PHPUnit 可执行文件:

    which phpunit

  2. 找到您正在运行的 php 可执行文件:

    which php

  3. sudo vi path/to/phpunit (可执行文件)

  4. 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.

  1. In terminal locate your PHPUnit executable:

    which phpunit

  2. Locate your running php executable:

    which php

  3. sudo vi path/to/phpunit (the executable)

  4. make sure that the first line referencing the php exectuable is actually the one from step two.

Solved my headache. :)

你的呼吸 2024-10-09 09:44:05

它无法连接到您的数据库。要么:

  • 您的数据库连接设置不正确。
  • 您的数据库未运行。
  • 存在网络配置错误。

It could not connect to your database. Either:

  • Your database connection settings are incorrect.
  • Your database is not running.
  • There is a networking misconfiguration.
对你再特殊 2024-10-09 09:44:05

尝试:

mysql_connect("127.0.0.1", "root", "123456") or die (mysql_error());
echo "Connected to MySQL";

有时MySQL服务器的权限设置对于“127.0.0.1”和“localhost”是不同的。如果是这种情况,你可以这样做:

mysql> GRANT ALL PRIVILEGES ON trackstar_dev.* TO 'root'@'127.0.0.1';

在你的 mysql 服务器上

try:

mysql_connect("127.0.0.1", "root", "123456") or die (mysql_error());
echo "Connected to MySQL";

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:

mysql> GRANT ALL PRIVILEGES ON trackstar_dev.* TO 'root'@'127.0.0.1';

on your mysql server

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文