@@ -8,7 +8,7 @@ |
||
8 | 8 | * @link https://github.com/kenjis/ci-phpunit-test |
9 | 9 | */ |
10 | 10 | |
11 | -require __DIR__ . '/Installer.php'; |
|
11 | +require __DIR__.'/Installer.php'; |
|
12 | 12 | |
13 | 13 | $installer = new Installer($argv); |
14 | 14 | $installer->install(); |
@@ -8,7 +8,7 @@ |
||
8 | 8 | * @link https://github.com/kenjis/ci-phpunit-test |
9 | 9 | */ |
10 | 10 | |
11 | -require __DIR__ . '/Installer.php'; |
|
11 | +require __DIR__.'/Installer.php'; |
|
12 | 12 | |
13 | 13 | $installer = new Installer($argv); |
14 | 14 | $installer->update(); |
@@ -10,192 +10,192 @@ |
||
10 | 10 | |
11 | 11 | class Installer |
12 | 12 | { |
13 | - const TEST_FOLDER = 'tests'; |
|
14 | - |
|
15 | - private $silent = false; |
|
16 | - private $app_dir = 'application'; |
|
17 | - private $pub_dir = 'public'; |
|
18 | - |
|
19 | - public function __construct($argv) |
|
20 | - { |
|
21 | - $this->parse_args($argv); |
|
22 | - } |
|
23 | - |
|
24 | - private function parse_args($argv) |
|
25 | - { |
|
26 | - $argc = count($argv); |
|
27 | - |
|
28 | - if ($argc === 1) { |
|
29 | - return; |
|
30 | - } |
|
31 | - |
|
32 | - for ($i = 1; $i <= $argc; $i++) { |
|
33 | - if (! isset($argv[$i])) { |
|
34 | - break; |
|
35 | - } |
|
36 | - |
|
37 | - switch ($argv[$i]) { |
|
38 | - // php install.php -s |
|
39 | - case '-s': |
|
40 | - $this->silent = true; |
|
41 | - break; |
|
42 | - |
|
43 | - // php install.php -a application |
|
44 | - case '-a': |
|
45 | - if (is_dir($argv[$i+1])) { |
|
46 | - $this->app_dir = $argv[$i+1]; |
|
47 | - } else { |
|
48 | - throw new Exception('No such directory: ' . $argv[$i+1]); |
|
49 | - } |
|
50 | - $i++; |
|
51 | - break; |
|
52 | - |
|
53 | - // php install.php -p public |
|
54 | - case '-p': |
|
55 | - if (is_dir($argv[$i+1])) { |
|
56 | - $this->pub_dir = $argv[$i+1]; |
|
57 | - } else { |
|
58 | - throw new Exception('No such directory: ' . $argv[$i+1]); |
|
59 | - } |
|
60 | - $i++; |
|
61 | - break; |
|
62 | - |
|
63 | - default: |
|
64 | - throw new Exception('Unknown argument: ' . $argv[$i]); |
|
65 | - } |
|
66 | - } |
|
67 | - } |
|
68 | - |
|
69 | - public function install() |
|
70 | - { |
|
71 | - $this->recursiveCopy( |
|
72 | - dirname(__FILE__) . '/application/tests', |
|
73 | - $this->app . '/' . static::TEST_FOLDER |
|
74 | - ); |
|
75 | - $this->fixPath($this->app, $this->pub); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Fix paths in Bootstrap.php |
|
80 | - */ |
|
81 | - private function fixPath() |
|
82 | - { |
|
83 | - $file = $this->app . '/' . static::TEST_FOLDER . '/Bootstrap.php'; |
|
84 | - $contents = file_get_contents($file); |
|
85 | - |
|
86 | - if (! file_exists('system')) { |
|
87 | - if (file_exists('vendor/codeigniter/framework/system')) { |
|
88 | - $contents = str_replace( |
|
89 | - '$system_path = \'../../system\';', |
|
90 | - '$system_path = \'../../vendor/codeigniter/framework/system\';', |
|
91 | - $contents |
|
92 | - ); |
|
93 | - } else { |
|
94 | - throw new Exception('Can\'t find "system" folder.'); |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - if (! file_exists('index.php')) { |
|
99 | - if (file_exists($pub . '/index.php')) { |
|
100 | - // CodeIgniter 3.0.6 and after |
|
101 | - $contents = str_replace( |
|
102 | - "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
|
103 | - "define('FCPATH', realpath(dirname(__FILE__).'/../../'. $pub).DIRECTORY_SEPARATOR);", |
|
104 | - $contents |
|
105 | - ); |
|
106 | - // CodeIgniter 3.0.5 and before |
|
107 | - $contents = str_replace( |
|
108 | - "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", |
|
109 | - "define('FCPATH', realpath(dirname(__FILE__).'/../../' . $pub).'/');", |
|
110 | - $contents |
|
111 | - ); |
|
112 | - } elseif (file_exists($this->app . '/public/index.php')) { |
|
113 | - // CodeIgniter 3.0.6 and after |
|
114 | - $contents = str_replace( |
|
115 | - "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
|
116 | - "define('FCPATH', realpath(dirname(__FILE__).'/../public').DIRECTORY_SEPARATOR);", |
|
117 | - $contents |
|
118 | - ); |
|
119 | - // CodeIgniter 3.0.5 and before |
|
120 | - $contents = str_replace( |
|
121 | - "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", |
|
122 | - "define('FCPATH', realpath(dirname(__FILE__).'/../public').'/');", |
|
123 | - $contents |
|
124 | - ); |
|
125 | - if ($this->app != 'application') { |
|
126 | - $contents = str_replace( |
|
127 | - "\$application_folder = '../../application';", |
|
128 | - "\$application_folder = '../../{$this->app}';", |
|
129 | - $contents |
|
130 | - ); |
|
131 | - } |
|
132 | - } else { |
|
133 | - throw new Exception('Can\'t find "index.php".'); |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - file_put_contents($file, $contents); |
|
138 | - } |
|
139 | - |
|
140 | - public function update() |
|
141 | - { |
|
142 | - $target_dir = $this->app . '/' . static::TEST_FOLDER . '/_ci_phpunit_test'; |
|
143 | - $this->recursiveUnlink($target_dir); |
|
144 | - $this->recursiveCopy( |
|
145 | - dirname(__FILE__) . '/application/tests/_ci_phpunit_test', |
|
146 | - $target_dir |
|
147 | - ); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Recursive Copy |
|
152 | - * |
|
153 | - * @param string $src |
|
154 | - * @param string $dst |
|
155 | - */ |
|
156 | - private function recursiveCopy($src, $dst) |
|
157 | - { |
|
158 | - @mkdir($dst, 0755); |
|
159 | - |
|
160 | - $iterator = new \RecursiveIteratorIterator( |
|
161 | - new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS), |
|
162 | - \RecursiveIteratorIterator::SELF_FIRST |
|
163 | - ); |
|
164 | - |
|
165 | - foreach ($iterator as $file) { |
|
166 | - if ($file->isDir()) { |
|
167 | - @mkdir($dst . '/' . $iterator->getSubPathName()); |
|
168 | - } else { |
|
169 | - $success = copy($file, $dst . '/' . $iterator->getSubPathName()); |
|
170 | - if ($success) { |
|
171 | - if (! $this->silent) { |
|
172 | - echo 'copied: ' . $dst . '/' . $iterator->getSubPathName() . PHP_EOL; |
|
173 | - } |
|
174 | - } |
|
175 | - } |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Recursive Unlink |
|
181 | - * |
|
182 | - * @param string $dir |
|
183 | - */ |
|
184 | - private function recursiveUnlink($dir) |
|
185 | - { |
|
186 | - $iterator = new \RecursiveIteratorIterator( |
|
187 | - new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS), |
|
188 | - \RecursiveIteratorIterator::CHILD_FIRST |
|
189 | - ); |
|
190 | - |
|
191 | - foreach ($iterator as $file) { |
|
192 | - if ($file->isDir()) { |
|
193 | - rmdir($file); |
|
194 | - } else { |
|
195 | - unlink($file); |
|
196 | - } |
|
197 | - } |
|
198 | - |
|
199 | - rmdir($dir); |
|
200 | - } |
|
13 | + const TEST_FOLDER = 'tests'; |
|
14 | + |
|
15 | + private $silent = false; |
|
16 | + private $app_dir = 'application'; |
|
17 | + private $pub_dir = 'public'; |
|
18 | + |
|
19 | + public function __construct($argv) |
|
20 | + { |
|
21 | + $this->parse_args($argv); |
|
22 | + } |
|
23 | + |
|
24 | + private function parse_args($argv) |
|
25 | + { |
|
26 | + $argc = count($argv); |
|
27 | + |
|
28 | + if ($argc === 1) { |
|
29 | + return; |
|
30 | + } |
|
31 | + |
|
32 | + for ($i = 1; $i <= $argc; $i++) { |
|
33 | + if (! isset($argv[$i])) { |
|
34 | + break; |
|
35 | + } |
|
36 | + |
|
37 | + switch ($argv[$i]) { |
|
38 | + // php install.php -s |
|
39 | + case '-s': |
|
40 | + $this->silent = true; |
|
41 | + break; |
|
42 | + |
|
43 | + // php install.php -a application |
|
44 | + case '-a': |
|
45 | + if (is_dir($argv[$i+1])) { |
|
46 | + $this->app_dir = $argv[$i+1]; |
|
47 | + } else { |
|
48 | + throw new Exception('No such directory: ' . $argv[$i+1]); |
|
49 | + } |
|
50 | + $i++; |
|
51 | + break; |
|
52 | + |
|
53 | + // php install.php -p public |
|
54 | + case '-p': |
|
55 | + if (is_dir($argv[$i+1])) { |
|
56 | + $this->pub_dir = $argv[$i+1]; |
|
57 | + } else { |
|
58 | + throw new Exception('No such directory: ' . $argv[$i+1]); |
|
59 | + } |
|
60 | + $i++; |
|
61 | + break; |
|
62 | + |
|
63 | + default: |
|
64 | + throw new Exception('Unknown argument: ' . $argv[$i]); |
|
65 | + } |
|
66 | + } |
|
67 | + } |
|
68 | + |
|
69 | + public function install() |
|
70 | + { |
|
71 | + $this->recursiveCopy( |
|
72 | + dirname(__FILE__) . '/application/tests', |
|
73 | + $this->app . '/' . static::TEST_FOLDER |
|
74 | + ); |
|
75 | + $this->fixPath($this->app, $this->pub); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Fix paths in Bootstrap.php |
|
80 | + */ |
|
81 | + private function fixPath() |
|
82 | + { |
|
83 | + $file = $this->app . '/' . static::TEST_FOLDER . '/Bootstrap.php'; |
|
84 | + $contents = file_get_contents($file); |
|
85 | + |
|
86 | + if (! file_exists('system')) { |
|
87 | + if (file_exists('vendor/codeigniter/framework/system')) { |
|
88 | + $contents = str_replace( |
|
89 | + '$system_path = \'../../system\';', |
|
90 | + '$system_path = \'../../vendor/codeigniter/framework/system\';', |
|
91 | + $contents |
|
92 | + ); |
|
93 | + } else { |
|
94 | + throw new Exception('Can\'t find "system" folder.'); |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + if (! file_exists('index.php')) { |
|
99 | + if (file_exists($pub . '/index.php')) { |
|
100 | + // CodeIgniter 3.0.6 and after |
|
101 | + $contents = str_replace( |
|
102 | + "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
|
103 | + "define('FCPATH', realpath(dirname(__FILE__).'/../../'. $pub).DIRECTORY_SEPARATOR);", |
|
104 | + $contents |
|
105 | + ); |
|
106 | + // CodeIgniter 3.0.5 and before |
|
107 | + $contents = str_replace( |
|
108 | + "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", |
|
109 | + "define('FCPATH', realpath(dirname(__FILE__).'/../../' . $pub).'/');", |
|
110 | + $contents |
|
111 | + ); |
|
112 | + } elseif (file_exists($this->app . '/public/index.php')) { |
|
113 | + // CodeIgniter 3.0.6 and after |
|
114 | + $contents = str_replace( |
|
115 | + "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
|
116 | + "define('FCPATH', realpath(dirname(__FILE__).'/../public').DIRECTORY_SEPARATOR);", |
|
117 | + $contents |
|
118 | + ); |
|
119 | + // CodeIgniter 3.0.5 and before |
|
120 | + $contents = str_replace( |
|
121 | + "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", |
|
122 | + "define('FCPATH', realpath(dirname(__FILE__).'/../public').'/');", |
|
123 | + $contents |
|
124 | + ); |
|
125 | + if ($this->app != 'application') { |
|
126 | + $contents = str_replace( |
|
127 | + "\$application_folder = '../../application';", |
|
128 | + "\$application_folder = '../../{$this->app}';", |
|
129 | + $contents |
|
130 | + ); |
|
131 | + } |
|
132 | + } else { |
|
133 | + throw new Exception('Can\'t find "index.php".'); |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + file_put_contents($file, $contents); |
|
138 | + } |
|
139 | + |
|
140 | + public function update() |
|
141 | + { |
|
142 | + $target_dir = $this->app . '/' . static::TEST_FOLDER . '/_ci_phpunit_test'; |
|
143 | + $this->recursiveUnlink($target_dir); |
|
144 | + $this->recursiveCopy( |
|
145 | + dirname(__FILE__) . '/application/tests/_ci_phpunit_test', |
|
146 | + $target_dir |
|
147 | + ); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Recursive Copy |
|
152 | + * |
|
153 | + * @param string $src |
|
154 | + * @param string $dst |
|
155 | + */ |
|
156 | + private function recursiveCopy($src, $dst) |
|
157 | + { |
|
158 | + @mkdir($dst, 0755); |
|
159 | + |
|
160 | + $iterator = new \RecursiveIteratorIterator( |
|
161 | + new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS), |
|
162 | + \RecursiveIteratorIterator::SELF_FIRST |
|
163 | + ); |
|
164 | + |
|
165 | + foreach ($iterator as $file) { |
|
166 | + if ($file->isDir()) { |
|
167 | + @mkdir($dst . '/' . $iterator->getSubPathName()); |
|
168 | + } else { |
|
169 | + $success = copy($file, $dst . '/' . $iterator->getSubPathName()); |
|
170 | + if ($success) { |
|
171 | + if (! $this->silent) { |
|
172 | + echo 'copied: ' . $dst . '/' . $iterator->getSubPathName() . PHP_EOL; |
|
173 | + } |
|
174 | + } |
|
175 | + } |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Recursive Unlink |
|
181 | + * |
|
182 | + * @param string $dir |
|
183 | + */ |
|
184 | + private function recursiveUnlink($dir) |
|
185 | + { |
|
186 | + $iterator = new \RecursiveIteratorIterator( |
|
187 | + new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS), |
|
188 | + \RecursiveIteratorIterator::CHILD_FIRST |
|
189 | + ); |
|
190 | + |
|
191 | + foreach ($iterator as $file) { |
|
192 | + if ($file->isDir()) { |
|
193 | + rmdir($file); |
|
194 | + } else { |
|
195 | + unlink($file); |
|
196 | + } |
|
197 | + } |
|
198 | + |
|
199 | + rmdir($dir); |
|
200 | + } |
|
201 | 201 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | } |
31 | 31 | |
32 | 32 | for ($i = 1; $i <= $argc; $i++) { |
33 | - if (! isset($argv[$i])) { |
|
33 | + if ( ! isset($argv[$i])) { |
|
34 | 34 | break; |
35 | 35 | } |
36 | 36 | |
@@ -42,26 +42,26 @@ discard block |
||
42 | 42 | |
43 | 43 | // php install.php -a application |
44 | 44 | case '-a': |
45 | - if (is_dir($argv[$i+1])) { |
|
46 | - $this->app_dir = $argv[$i+1]; |
|
45 | + if (is_dir($argv[$i + 1])) { |
|
46 | + $this->app_dir = $argv[$i + 1]; |
|
47 | 47 | } else { |
48 | - throw new Exception('No such directory: ' . $argv[$i+1]); |
|
48 | + throw new Exception('No such directory: '.$argv[$i + 1]); |
|
49 | 49 | } |
50 | 50 | $i++; |
51 | 51 | break; |
52 | 52 | |
53 | 53 | // php install.php -p public |
54 | 54 | case '-p': |
55 | - if (is_dir($argv[$i+1])) { |
|
56 | - $this->pub_dir = $argv[$i+1]; |
|
55 | + if (is_dir($argv[$i + 1])) { |
|
56 | + $this->pub_dir = $argv[$i + 1]; |
|
57 | 57 | } else { |
58 | - throw new Exception('No such directory: ' . $argv[$i+1]); |
|
58 | + throw new Exception('No such directory: '.$argv[$i + 1]); |
|
59 | 59 | } |
60 | 60 | $i++; |
61 | 61 | break; |
62 | 62 | |
63 | 63 | default: |
64 | - throw new Exception('Unknown argument: ' . $argv[$i]); |
|
64 | + throw new Exception('Unknown argument: '.$argv[$i]); |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | } |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | public function install() |
70 | 70 | { |
71 | 71 | $this->recursiveCopy( |
72 | - dirname(__FILE__) . '/application/tests', |
|
73 | - $this->app . '/' . static::TEST_FOLDER |
|
72 | + dirname(__FILE__).'/application/tests', |
|
73 | + $this->app.'/'.static::TEST_FOLDER |
|
74 | 74 | ); |
75 | 75 | $this->fixPath($this->app, $this->pub); |
76 | 76 | } |
@@ -80,10 +80,10 @@ discard block |
||
80 | 80 | */ |
81 | 81 | private function fixPath() |
82 | 82 | { |
83 | - $file = $this->app . '/' . static::TEST_FOLDER . '/Bootstrap.php'; |
|
83 | + $file = $this->app.'/'.static::TEST_FOLDER.'/Bootstrap.php'; |
|
84 | 84 | $contents = file_get_contents($file); |
85 | 85 | |
86 | - if (! file_exists('system')) { |
|
86 | + if ( ! file_exists('system')) { |
|
87 | 87 | if (file_exists('vendor/codeigniter/framework/system')) { |
88 | 88 | $contents = str_replace( |
89 | 89 | '$system_path = \'../../system\';', |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
98 | - if (! file_exists('index.php')) { |
|
99 | - if (file_exists($pub . '/index.php')) { |
|
98 | + if ( ! file_exists('index.php')) { |
|
99 | + if (file_exists($pub.'/index.php')) { |
|
100 | 100 | // CodeIgniter 3.0.6 and after |
101 | 101 | $contents = str_replace( |
102 | 102 | "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | "define('FCPATH', realpath(dirname(__FILE__).'/../../' . $pub).'/');", |
110 | 110 | $contents |
111 | 111 | ); |
112 | - } elseif (file_exists($this->app . '/public/index.php')) { |
|
112 | + } elseif (file_exists($this->app.'/public/index.php')) { |
|
113 | 113 | // CodeIgniter 3.0.6 and after |
114 | 114 | $contents = str_replace( |
115 | 115 | "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
@@ -139,10 +139,10 @@ discard block |
||
139 | 139 | |
140 | 140 | public function update() |
141 | 141 | { |
142 | - $target_dir = $this->app . '/' . static::TEST_FOLDER . '/_ci_phpunit_test'; |
|
142 | + $target_dir = $this->app.'/'.static::TEST_FOLDER.'/_ci_phpunit_test'; |
|
143 | 143 | $this->recursiveUnlink($target_dir); |
144 | 144 | $this->recursiveCopy( |
145 | - dirname(__FILE__) . '/application/tests/_ci_phpunit_test', |
|
145 | + dirname(__FILE__).'/application/tests/_ci_phpunit_test', |
|
146 | 146 | $target_dir |
147 | 147 | ); |
148 | 148 | } |
@@ -164,12 +164,12 @@ discard block |
||
164 | 164 | |
165 | 165 | foreach ($iterator as $file) { |
166 | 166 | if ($file->isDir()) { |
167 | - @mkdir($dst . '/' . $iterator->getSubPathName()); |
|
167 | + @mkdir($dst.'/'.$iterator->getSubPathName()); |
|
168 | 168 | } else { |
169 | - $success = copy($file, $dst . '/' . $iterator->getSubPathName()); |
|
169 | + $success = copy($file, $dst.'/'.$iterator->getSubPathName()); |
|
170 | 170 | if ($success) { |
171 | - if (! $this->silent) { |
|
172 | - echo 'copied: ' . $dst . '/' . $iterator->getSubPathName() . PHP_EOL; |
|
171 | + if ( ! $this->silent) { |
|
172 | + echo 'copied: '.$dst.'/'.$iterator->getSubPathName().PHP_EOL; |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | } |