Skip to content

Commit

Permalink
Making the init script take variables from the environment
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jun 16, 2013
1 parent b7204f6 commit 1c8caa2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 67 deletions.
69 changes: 4 additions & 65 deletions .travis.yml
Expand Up @@ -5,9 +5,9 @@ php:
- 5.5

env:
- DB=mysql
- DB=pgsql
- DB=sqlite
- DB=mysql db_class='Cake\Database\Driver\Mysql' db_dsn='mysql:host=0.0.0.0;dbname=cakephp_test;charset=utf8' db_database='cakephp_test'

This comment has been minimized.

Copy link
@renan

renan Jun 16, 2013

Contributor

No more cross database tests?

This comment has been minimized.

Copy link
@markstory

markstory Jun 17, 2013

Member

The ORM layer doesn't support it yet.

- DB=pgsql db_class='Cake\Database\Driver\Postgres' db_dsn='pgsql:host=127.0.0.1;dbname=cakephp_test;charset=utf8' db_database="cakephp_test"
- DB=sqlite db_class='Cake\Database\Driver\Sqlite' db_dsn='sqlite::memory:'

matrix:
include:
Expand All @@ -28,70 +28,9 @@ before_script:
- sh -c "if [ '$PHPCS' = '1' ]; then pear install --alldeps cakephp/CakePHP_CodeSniffer; fi"
- phpenv rehash
- set +H
- echo "<?php
namespace App\Config;
use Cake\Core\Configure;
\$db = 'mysql';
if (!empty(\$_SERVER['DB'])) {
\$db = \$_SERVER['DB'];
}
\$identities = array(
'mysql' => array(
'datasource' => 'Cake\Database\Driver\Mysql',
'host' => '0.0.0.0',
'login' => 'travis',
'database' => array(
'default' => 'cakephp_test',
'test' => 'cakephp_test',
'test2' => 'cakephp_test2',
'test_database_three' => 'cakephp_test3'
),
),
'pgsql' => array(
'datasource' => 'Cake\Database\Driver\Postgres',
'host' => '127.0.0.1',
'login' => 'postgres',
'database' => 'cakephp_test',
'schema' => array(
'default' => 'public',
'test' => 'public',
'test2' => 'test2',
'test_database_three' => 'test3'
)
),
'sqlite' => array(
'datasource' => 'Cake\Database\Driver\Sqlite',
'database' => array(
'default' => ':memory:',
'test' => ':memory:',
'test2' => '/tmp/cakephp_test2.db',
'test_database_three' => '/tmp/cakephp_test3.db'
),
)
);
\$default = array(
'persistent' => false,
'host' => '',
'login' => '',
'password' => '',
'database' => '',
'prefix' => ''
);
\$datasources = array();
foreach (array('default', 'test', 'test2', 'test_database_three') as \$source) {
\$config = array_merge(\$default, \$identities[\$db]);
if (is_array(\$config['database'])) {
\$config['database'] = \$config['database'][\$source];
}
if (!empty(\$config['schema']) && is_array(\$config['schema'])) {
\$config['schema'] = \$config['schema'][\$source];
}
\$datasources[\$source] = \$config;
}
Configure::write('Datasource', \$datasources);" > App/Config/datasources.php

script:
- sh -c "if [ '$PHPCS' != '1' ]; then ./lib/Cake/Console/cake test core AllTests --stderr; else phpcs -p --extensions=php --standard=CakePHP ./lib/Cake; fi"
- sh -c "if [ '$PHPCS' != '1' ]; then cd /lib/Cake && phpunit --stderr; else phpcs -p --extensions=php --standard=CakePHP ./lib/Cake; fi"

notifications:
email: false
7 changes: 5 additions & 2 deletions lib/Cake/Test/init.php
Expand Up @@ -60,14 +60,17 @@
]);

Cake\Core\Configure::write('Datasource.test', [
'datasource' => 'Cake\Database\Driver\Sqlite'
'datasource' => getenv('db_class'),
'dsn' => getenv('db_dsn'),
'database' => getenv('db_database'),
'login' => getenv('db_login'),
'password' => getenv('db_password')
]);

Cake\Core\Configure::write('Session', [
'defaults' => 'php'
]);


Cake\Core\Configure::write('Log.debug', [
'engine' => 'Cake\Log\Engine\FileLog',
'levels' => ['notice', 'info', 'debug'],
Expand Down

0 comments on commit 1c8caa2

Please sign in to comment.