所以我在 CakePHP 中有一个项目。推送我的代码时,Travis CI 应该运行我的测试。我的测试名为 ToolTest,其 Fixture 为 ToolFixture。
我的 .travis.yml 如下所示:
language: php
php: 5.3
services:
- mysql
before_script:
- sh -c "mysql -e 'CREATE DATABASE test;'"
- chmod -R 777 project/tmp
- echo "<?php
class DATABASE_CONFIG {
public \$test = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'database' => 'test',
'host' => 'localhost',
'login' => 'travis'
);
}" > project/database.php
script:
sudo project/Console/cake test app Model/Tool --stderr
travis 上的错误 strack trace 说:
Fatal error: Uncaught exception 'MissingConnectionException' with message 'Database connection "Mysql" is missing, or could not be created.' in /home/travis/build/project/lib/Cake/Model/Datasource/Database/Mysql.php:194
Error: Database connection "Mysql" is missing, or could not be created.
我已经尝试过“127.0.0.1”而不是本地主机,同样的错误消息。在 VM 上运行我的测试时,测试通过。
我注意到的是:
如果我没有运行脚本命令,travis 是成功的,那么创建 db 测试和编写 database.php 应该可以正常工作,对吧?
我的测试和夹具非常简约。
工具测试:
public function setUp()
{
parent::setUp();
$this->Tool = ClassRegistry::init('Tool');
}
public function testFindListById()
{
$result = $this->Tool->findListById(2);
$expected = array(
2 => 'Java'
);
$this->assertEquals($expected, $result);
}
工具夹具:
class ToolFixture extends CakeTestFixture
{
public $useDbConfig = 'test';
public $fields = array(
'id' => 'string',
'name' => 'string'
);
public $records = array(
array(
'id' => 1,
'name' => 'HTML'
),
array(
'id' => 2,
'name' => 'Java'
)
);
}
我错过了什么?我已经被这个问题困扰好几天了……有什么想法吗?很高兴为您提供帮助!
最佳答案
所以我发现我没有在正确的文件夹中写入我的数据库配置.. 而不是
>project/database.php
应该是
> project/Config/database.php
哎呀..
关于php - 使用 Travis CI 触发测试时无法访问 CakePHP fixture db,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39526592/