Janet Do Janet Do - 2 months ago 12
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

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


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 '127.0.0.1' 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.

ToolTest:


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);
}


ToolFixture:

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'

)
);
}


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

Answer

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

>project/database.php 

It should have been

> project/Config/database.php

Jeez..