1: <?php
2:
3: class JenkinsBuildShell extends Shell {
4:
5: 6: 7: 8: 9:
10: public function getOptionParser() {
11: $parser = parent::getOptionParser();
12: $parser->description("Configure database and execute tests.");
13: $parser->addOptions(
14: array(
15: 'login' => array(
16: 'default' => 'jenkins',
17: ),
18: 'password' => array(
19: 'default' => 'jenkins',
20: ),
21: )
22: );
23:
24: $parser->addArguments(array(
25: 'database' => array(
26: 'required' => true,
27: )
28: ));
29: return $parser;
30: }
31:
32: public function main() {
33: $this->_configureDatabase();
34: $this->dispatchShell('Migrations.migration', 'run', '0');
35: $this->dispatchShell('Base.migration_all_plugins', '--reset');
36: $this->dispatchShell('test', 'PluginManager', 'AllLoadedPluginsNoMigrations');
37: }
38:
39: private function _configureDatabase() {
40: file_put_contents(APP . DS . 'Config' . DS . 'database.php', <<<EOT
41: <?php
42:
43: class DATABASE_CONFIG {
44:
45: public \$default = array(
46: 'datasource' => 'Database/Mysql',
47: 'host' => 'localhost',
48: 'database' => '{$this->args[0]}',
49: 'login' => '{$this->params['login']}',
50: 'password' => '{$this->params['password']}',
51: 'encoding' => 'utf8',
52: );
53: public \$test = array(
54: 'datasource' => 'Database/Mysql',
55: 'host' => 'localhost',
56: 'database' => '{$this->args[0]}',
57: 'login' => '{$this->params['login']}',
58: 'password' => '{$this->params['password']}',
59: 'encoding' => 'utf8',
60: 'prefix' => 'test_',
61: );
62:
63: }
64: EOT
65: );
66: }
67:
68: }