1 | <?php |
---|
2 | |
---|
3 | $_lib_dir = '/home/joshua/devel/svn/symfony/1.0/lib'; |
---|
4 | $_data_dir = '/home/joshua/devel/svn/symfony/1.0/data'; |
---|
5 | |
---|
6 | require_once($_lib_dir.'/vendor/lime/lime.php'); |
---|
7 | require_once($_lib_dir.'/util/sfFinder.class.php'); |
---|
8 | require_once($_lib_dir.'/util/sfToolkit.class.php'); |
---|
9 | |
---|
10 | define('DS', DIRECTORY_SEPARATOR); |
---|
11 | |
---|
12 | class symfony_cmd |
---|
13 | { |
---|
14 | public $php_cli = null; |
---|
15 | public $data_dir = null; |
---|
16 | public $tmp_dir = null; |
---|
17 | public $t = null; |
---|
18 | public $current_dir = null; |
---|
19 | |
---|
20 | public function initialize($t, $data_dir) |
---|
21 | { |
---|
22 | $this->t = $t; |
---|
23 | $this->data_dir = $data_dir; |
---|
24 | |
---|
25 | $this->tmp_dir = sfToolkit::getTmpDir().DIRECTORY_SEPARATOR.'symfony_cmd'; |
---|
26 | |
---|
27 | if (is_dir($this->tmp_dir)) |
---|
28 | { |
---|
29 | $this->clearTmpDir(); |
---|
30 | rmdir($this->tmp_dir); |
---|
31 | } |
---|
32 | |
---|
33 | mkdir($this->tmp_dir, 0777); |
---|
34 | |
---|
35 | $this->current_dir = getcwd(); |
---|
36 | chdir($this->tmp_dir); |
---|
37 | |
---|
38 | $this->php_cli = sfToolkit::getPhpCli(); |
---|
39 | } |
---|
40 | |
---|
41 | public function shutdown() |
---|
42 | { |
---|
43 | $this->clearTmpDir(); |
---|
44 | rmdir($this->tmp_dir); |
---|
45 | chdir($this->current_dir); |
---|
46 | } |
---|
47 | |
---|
48 | protected function clearTmpDir() |
---|
49 | { |
---|
50 | sfToolkit::clearDirectory($this->tmp_dir); |
---|
51 | } |
---|
52 | |
---|
53 | public function execute_command($cmd, $test = true) |
---|
54 | { |
---|
55 | ob_start(); |
---|
56 | passthru(sprintf('%s -d html_errors=off -d open_basedir= -q "%s" %s 2>&1', $this->php_cli, $this->data_dir . '/bin/symfony', $cmd), $return); |
---|
57 | $content = ob_get_clean(); |
---|
58 | if ($test) |
---|
59 | { |
---|
60 | $this->t->cmp_ok($return, '<=', 0, sprintf('"symfony %s" returns ok', $cmd)); |
---|
61 | } |
---|
62 | |
---|
63 | return $content; |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | function copyr($source_dir, $dest_dir) |
---|
68 | { |
---|
69 | $files = sfFinder::type('file')->name('*')->ignore_version_control()->in($source_dir); |
---|
70 | |
---|
71 | // copy source files |
---|
72 | foreach ($files as $file) |
---|
73 | { |
---|
74 | $dest = str_replace($source_dir, $dest_dir, $file); |
---|
75 | |
---|
76 | if (!file_exists(dirname($dest))) |
---|
77 | { |
---|
78 | mkdir(dirname($dest), 0777, true); |
---|
79 | } |
---|
80 | |
---|
81 | copy($file, $dest); |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | function rewrite_config($config_path) |
---|
86 | { |
---|
87 | $config = file_get_contents($config_path); |
---|
88 | |
---|
89 | $config = str_replace( |
---|
90 | array( |
---|
91 | 'addon.propel.builder.SfPeerBuilder', |
---|
92 | 'addon.propel.builder.SfObjectBuilder', |
---|
93 | ), |
---|
94 | array( |
---|
95 | 'plugins.sfPropel13Plugin.lib.propel.builder.SfPeerBuilder', |
---|
96 | 'plugins.sfPropel13Plugin.lib.propel.builder.SfObjectBuilder', |
---|
97 | ), |
---|
98 | $config |
---|
99 | ); |
---|
100 | |
---|
101 | file_put_contents($config_path, $config); |
---|
102 | } |
---|
103 | |
---|
104 | $t = new lime_test(10, new lime_output_color()); |
---|
105 | $c = new symfony_cmd(); |
---|
106 | $c->initialize($t, $_data_dir); |
---|
107 | |
---|
108 | // setup project |
---|
109 | $content = $c->execute_command('init-project myproject', false); |
---|
110 | $content = $c->execute_command('init-app frontend', false); |
---|
111 | |
---|
112 | // sfPakePropel |
---|
113 | copy(dirname(__FILE__).'/fixtures/schema.yml', $c->tmp_dir.DS.'config'.DS.'schema.yml'); |
---|
114 | copyr(realpath(dirname(__FILE__) . '/../../'), $c->tmp_dir.DS.'plugins'.DS.'sfPropel13Plugin'); |
---|
115 | rewrite_config($c->tmp_dir.DS.'config'.DS.'propel.ini'); |
---|
116 | |
---|
117 | $content = $c->execute_command('propel-13-build-sql'); |
---|
118 | $t->ok(file_exists($c->tmp_dir.DS.'data'.DS.'sql'.DS.'lib.model.schema.sql'), '"propel-build-sql" creates a "schema.sql" file under "data/sql" directory'); |
---|
119 | |
---|
120 | $content = $c->execute_command('propel-13-build-model'); |
---|
121 | $t->ok(file_exists($c->tmp_dir.DS.'lib'.DS.'model'.DS.'Article.php'), '"propel-build-model" creates model classes under "lib/model" directory'); |
---|
122 | |
---|
123 | // sfPakePropelCrudGenerator |
---|
124 | $content = $c->execute_command('propel-13-init-crud frontend articleInitCrud Article'); |
---|
125 | $t->ok(file_exists($c->tmp_dir.DS.'apps'.DS.'frontend'.DS.'modules'.DS.'articleInitCrud'.DS.'config'.DS.'generator.yml'), '"propel-init-crud" initializes a CRUD module'); |
---|
126 | |
---|
127 | $content = $c->execute_command('propel-13-generate-crud frontend articleGenCrud Article'); |
---|
128 | $t->ok(is_dir($c->tmp_dir.DS.'apps'.DS.'frontend'.DS.'modules'.DS.'articleGenCrud'), '"propel-generate-crud" generates a CRUD module'); |
---|
129 | |
---|
130 | // sfPakePropelAdminGenerator |
---|
131 | $content = $c->execute_command('propel-13-init-admin frontend articleInitAdmin Article'); |
---|
132 | $t->ok(file_exists($c->tmp_dir.DS.'apps'.DS.'frontend'.DS.'modules'.DS.'articleInitAdmin'.DS.'config'.DS.'generator.yml'), '"propel-init-admin" initializes an admin generator module'); |
---|
133 | |
---|
134 | $c->shutdown(); |
---|