Skip to content

Commit

Permalink
Merge 044fa6a into 34eb4c6
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Apr 15, 2018
2 parents 34eb4c6 + 044fa6a commit eca3370
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion install.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @link https://github.com/kenjis/ci-phpunit-test
*/

require __DIR__ . '/Installer.php';
require __DIR__.'/lib/Installer.php';

$installer = new Installer($argv);
$installer->install();
32 changes: 16 additions & 16 deletions Installer.php → lib/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private function parse_args($argv)
if (is_dir($argv[$i+1])) {
$this->app_dir = $argv[$i+1];
} else {
throw new Exception('No such directory: ' . $argv[$i+1]);
throw new Exception('No such directory: '.$argv[$i+1]);
}
$i++;
break;
Expand All @@ -54,22 +54,22 @@ private function parse_args($argv)
if (is_dir($argv[$i+1])) {
$this->pub_dir = $argv[$i+1];
} else {
throw new Exception('No such directory: ' . $argv[$i+1]);
throw new Exception('No such directory: '.$argv[$i+1]);
}
$i++;
break;

default:
throw new Exception('Unknown argument: ' . $argv[$i]);
throw new Exception('Unknown argument: '.$argv[$i]);
}
}
}

public function install()
{
$this->recursiveCopy(
dirname(__FILE__) . '/application/tests',
$this->app_dir . '/' . $this->test_dir
dirname(dirname(__FILE__)).'/application/tests',
$this->app_dir.'/'.$this->test_dir
);
$this->fixPath();
}
Expand All @@ -79,7 +79,7 @@ public function install()
*/
private function fixPath()
{
$file = $this->app_dir . '/' . $this->test_dir . '/Bootstrap.php';
$file = $this->app_dir.'/'.$this->test_dir.'/Bootstrap.php';
$contents = file_get_contents($file);

if (! file_exists('system')) {
Expand All @@ -95,20 +95,20 @@ private function fixPath()
}

if (! file_exists('index.php')) {
if (file_exists($this->pub_dir . '/index.php')) {
if (file_exists($this->pub_dir.'/index.php')) {
// CodeIgniter 3.0.6 and after
$contents = str_replace(
"define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);",
"define('FCPATH', realpath(dirname(__FILE__).'/../../'. $this->pub_dir).DIRECTORY_SEPARATOR);",
"define('FCPATH', realpath(dirname(__FILE__).'/../../{$this->pub_dir}').DIRECTORY_SEPARATOR);",
$contents
);
// CodeIgniter 3.0.5 and before
$contents = str_replace(
"define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');",
"define('FCPATH', realpath(dirname(__FILE__).'/../../' . $this->pub_dir).'/');",
"define('FCPATH', realpath(dirname(__FILE__).'/../../{$this->pub_dir}').'/');",
$contents
);
} elseif (file_exists($this->app_dir . '/public/index.php')) {
} elseif (file_exists($this->app_dir.'/public/index.php')) {
// CodeIgniter 3.0.6 and after
$contents = str_replace(
"define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);",
Expand All @@ -121,7 +121,7 @@ private function fixPath()
"define('FCPATH', realpath(dirname(__FILE__).'/../public').'/');",
$contents
);
if ($this->app_dir != 'application') {
if ($this->app_dir !== 'application') {
$contents = str_replace(
"\$application_folder = '../../application';",
"\$application_folder = '../../{$this->app_dir}';",
Expand All @@ -138,10 +138,10 @@ private function fixPath()

public function update()
{
$target_dir = $this->app_dir . '/' . $this->test_dir . '/_ci_phpunit_test';
$target_dir = $this->app_dir.'/'.$this->test_dir.'/_ci_phpunit_test';
$this->recursiveUnlink($target_dir);
$this->recursiveCopy(
dirname(__FILE__) . '/application/tests/_ci_phpunit_test',
dirname(dirname(__FILE__)).'/application/tests/_ci_phpunit_test',
$target_dir
);
}
Expand All @@ -163,12 +163,12 @@ private function recursiveCopy($src, $dst)

foreach ($iterator as $file) {
if ($file->isDir()) {
@mkdir($dst . '/' . $iterator->getSubPathName());
@mkdir($dst.'/'.$iterator->getSubPathName());
} else {
$success = copy($file, $dst . '/' . $iterator->getSubPathName());
$success = copy($file, $dst.'/'.$iterator->getSubPathName());
if ($success) {
if (! $this->silent) {
echo 'copied: ' . $dst . '/' . $iterator->getSubPathName() . PHP_EOL;
echo 'copied: '.$dst.'/'.$iterator->getSubPathName().PHP_EOL;
}
}
}
Expand Down

0 comments on commit eca3370

Please sign in to comment.