Janet Do Janet Do - 10 months ago 45
MySQL Question

Can't access CakePHP fixture db when triggering test with Travis CI

so I have a project in CakePHP. When pushing my code, Travis CI should run my test. My Test is named ToolTest and its Fixture is ToolFixture.

My .travis.yml looks as following:

language: php

php: 5.3

- mysql

- sh -c "mysql -e 'CREATE DATABASE test;'"
- chmod -R 777 project/tmp
- echo "<?php
public \$test = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'database' => 'test',
'host' => 'localhost',
'login' => 'travis'
}" > project/database.php

sudo project/Console/cake test app Model/Tool --stderr

The error strack trace on travis says:

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.

I already tried '' instead of localhost, same error messages. When running my test on the VM, the test passes.

What I've noticed:

If I'm not running the script command, travis is successful, so creating the db test and writing the database.php should work fine, right?

My test and fixture are pretty minimalistic.


public function 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(
'id' => 1,
'name' => 'HTML'

'id' => 2,
'name' => 'Java'


What am I missing? I've been stuck with this problem for days..Any ideas? Glad for any help!

Answer Source

So I found out that I didn't write my database config in the correct folder.. Instead of


It should have been

> project/Config/database.php