【问题标题】:Using multiple database sources while writing cake test cases in CAKEPHP 1.3在 CAKEPHP 1.3 中编写蛋糕测试用例时使用多个数据库源
【发布时间】:2019-02-18 13:22:55
【问题描述】:

如果我通过 url 运行代码,它就可以工作(例如:http://localhost:8080/projects/emailNewProject/2008098

但如果我尝试通过http://localhost:8080/test.php?show=cases&app=true 访问它 它抛出错误:模型客户缺少数据库表

我尝试使用以下方法更改控制器中的数据源:

Configure::write('currentDataSource', 'testdb');
$dataSource = Configure::read('currentDataSource');
$this->setDataSource($dataSource);

还是不影响!!

class ProjectsControllerTest extends CakeTestCase{
    function testEmailNewProject()
        {
            $id     = 2008098;
            $result = $this->testAction('/projects/emailNewProject', array('fixturize' => true, 'data' => $id, 'method' => 'post'));
            debug($result);
        }
    }

【问题讨论】:

  • 此链接中给出的示例enter link description here
  • @Chintan 我正在开发一个基于 Cakephp 1.3 的遗留项目,我没有尝试连接任何远程数据库。所有数据源都在本地主机中。

标签: cakephp cakephp-1.3


【解决方案1】:

这可能是因为您的 Project 模型(hasOne、belongsTo 等)与 Customer 模型相关联,而您没有 Customer 的固定装置。这就是告诉测试引擎为测试数据库创建哪些数据库表的原因。

您可以在此处阅读更多相关信息:https://book.cakephp.org/1.3/en/The-Manual/Common-Tasks-With-CakePHP/Testing.html#preparing-test-data

如果仍有问题,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-13
    • 2018-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多