【问题标题】:Cakephp 3.0 having error when running phpunit testcase from bookCakephp 3.0 从书中运行 phpunit 测试用例时出错
【发布时间】:2015-06-26 16:37:59
【问题描述】:

我已经安装了phpunit,但是在运行phpunit tests/TestCase/Model/Table/ArticlesTableTest时仍然报错

我的测试模型和控制器是从 cake bake 命令生成的

我从他们的文档中遵循了本指南 http://book.cakephp.org/3.0/en/development/testing.html

这是我从控制台得到的

There were 2 errors:

1) App\Test\TestCase\Model\Table\ArticlesTableTest::testInitialize
Cake\Datasource\Exception\MissingDatasourceConfigException: The datasource confi
guration "default" was not found.

D:\web\xampp\htdocs\test\cakeblog-test\vendor\cakephp\cakephp\src\Datasourc
e\ConnectionManager.php:187
D:\web\xampp\htdocs\test\cakeblog-test\vendor\cakephp\cakephp\src\ORM\Table
Registry.php:191
D:\web\xampp\htdocs\test\cakeblog-test\tests\TestCase\Model\Table\PersonTab
leTest.php:32

【问题讨论】:

  • 嗯,错误信息看起来很简单。您是否检查过您的应用配置中是否存在default 连接?
  • 我在 config/app.php 的 Datasources 'test' => [ 'datasource' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'localhost', 'username' => 'myUserName', 'password' => 'myPassword', 'database' => 'test_database' ],
  • 也就是说,没有default连接?
  • 我的 config/app.php 中已经有 defaulttest 数据源连接,它们来自 config/app.default.php,目前是访问localhost/mycake-app 时工作。但是当我运行 phpunit tests/TestCase/Model/Table/ArticlesTableTest 时我仍然遇到错误
  • 你能显示你的 phpunit.xml 文件吗?

标签: phpunit cakephp-3.0


【解决方案1】:

我有完全相同的错误。对我来说,问题出在命令提示符下,当我在 PowerShell 中运行测试时,一切正常。 如果您使用的是 Windows,请尝试在 PowerShell 中运行您的测试。

【讨论】:

    【解决方案2】:

    可能重复here

    我在使用 Ubuntu 14.04(这里没有 PowerShell)时遇到了同样的问题。就我而言,问题是我从错误的位置运行测试。根据documentation,您需要站在应用根目录中才能正确运行测试。

    所以在你的情况下,它会是这样的:

    $ cd /path/to/your/app
    $ vendor/bin/phpunit tests/TestCase/Model/Table/ArticlesTable
    

    【讨论】:

      猜你喜欢
      • 2015-08-28
      • 1970-01-01
      • 1970-01-01
      • 2017-08-05
      • 2016-03-23
      • 1970-01-01
      • 2014-05-08
      • 2012-03-22
      • 2013-08-17
      相关资源
      最近更新 更多