@@ -69,28 +69,28 @@ |
||
| 69 | 69 | */ |
| 70 | 70 | switch (ENVIRONMENT) |
| 71 | 71 | { |
| 72 | - case 'testing': |
|
| 73 | - case 'development': |
|
| 74 | - error_reporting(-1); |
|
| 75 | - ini_set('display_errors', 1); |
|
| 76 | - break; |
|
| 77 | - |
|
| 78 | - case 'production': |
|
| 79 | - ini_set('display_errors', 0); |
|
| 80 | - if (version_compare(PHP_VERSION, '5.3', '>=')) |
|
| 81 | - { |
|
| 82 | - error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
|
| 83 | - } |
|
| 84 | - else |
|
| 85 | - { |
|
| 86 | - error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
|
| 87 | - } |
|
| 88 | - break; |
|
| 89 | - |
|
| 90 | - default: |
|
| 91 | - header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); |
|
| 92 | - echo 'The application environment is not set correctly.'; |
|
| 93 | - exit(1); // EXIT_ERROR |
|
| 72 | + case 'testing': |
|
| 73 | + case 'development': |
|
| 74 | + error_reporting(-1); |
|
| 75 | + ini_set('display_errors', 1); |
|
| 76 | + break; |
|
| 77 | + |
|
| 78 | + case 'production': |
|
| 79 | + ini_set('display_errors', 0); |
|
| 80 | + if (version_compare(PHP_VERSION, '5.3', '>=')) |
|
| 81 | + { |
|
| 82 | + error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
|
| 83 | + } |
|
| 84 | + else |
|
| 85 | + { |
|
| 86 | + error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
|
| 87 | + } |
|
| 88 | + break; |
|
| 89 | + |
|
| 90 | + default: |
|
| 91 | + header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); |
|
| 92 | + echo 'The application environment is not set correctly.'; |
|
| 93 | + exit(1); // EXIT_ERROR |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /* |
@@ -251,10 +251,10 @@ |
||
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
| 254 | - * Recursive Unlink |
|
| 255 | - * |
|
| 256 | - * @param string $dir |
|
| 257 | - */ |
|
| 254 | + * Recursive Unlink |
|
| 255 | + * |
|
| 256 | + * @param string $dir |
|
| 257 | + */ |
|
| 258 | 258 | protected static function recursiveUnlink($dir) |
| 259 | 259 | { |
| 260 | 260 | if (! is_dir($dir)) |
@@ -37,12 +37,12 @@ |
||
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | - * Patch on constant |
|
| 41 | - * |
|
| 42 | - * @param type $constant |
|
| 43 | - * @param type $value |
|
| 44 | - * @param type $class_method |
|
| 45 | - */ |
|
| 40 | + * Patch on constant |
|
| 41 | + * |
|
| 42 | + * @param type $constant |
|
| 43 | + * @param type $value |
|
| 44 | + * @param type $class_method |
|
| 45 | + */ |
|
| 46 | 46 | public static function patchConstant($constant, $value, $class_method = null) |
| 47 | 47 | { |
| 48 | 48 | ConstProxy::patch($constant, $value, $class_method); |
@@ -52,71 +52,71 @@ |
||
| 52 | 52 | */ |
| 53 | 53 | final class TestSuiteProvider |
| 54 | 54 | { |
| 55 | - /** |
|
| 56 | - * phpunit configuration file |
|
| 57 | - * |
|
| 58 | - * @var string |
|
| 59 | - */ |
|
| 60 | - private static $file; |
|
| 55 | + /** |
|
| 56 | + * phpunit configuration file |
|
| 57 | + * |
|
| 58 | + * @var string |
|
| 59 | + */ |
|
| 60 | + private static $file; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * constructor |
|
| 64 | - */ |
|
| 65 | - private function __construct() {} |
|
| 62 | + /** |
|
| 63 | + * constructor |
|
| 64 | + */ |
|
| 65 | + private function __construct() {} |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * set the phpunit configuration file |
|
| 69 | - * |
|
| 70 | - * @param string $file the path or filename of the phunit configuration file |
|
| 71 | - */ |
|
| 72 | - public static function setConfigurationFile($file) |
|
| 73 | - { |
|
| 74 | - static::$file = $file; |
|
| 75 | - } |
|
| 67 | + /** |
|
| 68 | + * set the phpunit configuration file |
|
| 69 | + * |
|
| 70 | + * @param string $file the path or filename of the phunit configuration file |
|
| 71 | + */ |
|
| 72 | + public static function setConfigurationFile($file) |
|
| 73 | + { |
|
| 74 | + static::$file = $file; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * get the phpunit test suite instance |
|
| 79 | - * |
|
| 80 | - * @return PHPUnit_Framework_TestSuite returns the phpunit test suite instance |
|
| 81 | - * @throws FileNotFoundException if the file is not found |
|
| 82 | - */ |
|
| 83 | - public static function suite() |
|
| 84 | - { |
|
| 85 | - $file = static::checkConfigurationFile( |
|
| 86 | - static::getConfigurationFile() |
|
| 87 | - ); |
|
| 77 | + /** |
|
| 78 | + * get the phpunit test suite instance |
|
| 79 | + * |
|
| 80 | + * @return PHPUnit_Framework_TestSuite returns the phpunit test suite instance |
|
| 81 | + * @throws FileNotFoundException if the file is not found |
|
| 82 | + */ |
|
| 83 | + public static function suite() |
|
| 84 | + { |
|
| 85 | + $file = static::checkConfigurationFile( |
|
| 86 | + static::getConfigurationFile() |
|
| 87 | + ); |
|
| 88 | 88 | |
| 89 | - return PHPUnit_Util_Configuration::getInstance($file) |
|
| 90 | - ->getTestSuiteConfiguration(); |
|
| 91 | - } |
|
| 89 | + return PHPUnit_Util_Configuration::getInstance($file) |
|
| 90 | + ->getTestSuiteConfiguration(); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * get the phpunit configuration file |
|
| 95 | - * |
|
| 96 | - * @return string |
|
| 97 | - */ |
|
| 98 | - private static function getConfigurationFile() |
|
| 99 | - { |
|
| 100 | - static::$file = isset(static::$file) |
|
| 101 | - ? static::$file |
|
| 102 | - : TESTPATH.'phpunit.xml'; |
|
| 93 | + /** |
|
| 94 | + * get the phpunit configuration file |
|
| 95 | + * |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 98 | + private static function getConfigurationFile() |
|
| 99 | + { |
|
| 100 | + static::$file = isset(static::$file) |
|
| 101 | + ? static::$file |
|
| 102 | + : TESTPATH.'phpunit.xml'; |
|
| 103 | 103 | |
| 104 | - return static::$file; |
|
| 105 | - } |
|
| 104 | + return static::$file; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * check the given file |
|
| 109 | - * |
|
| 110 | - * @param string $file file to check |
|
| 111 | - * @return string returns the file if it is valid |
|
| 112 | - * @throws FileNotFoundException if the file is not found |
|
| 113 | - */ |
|
| 114 | - private static function checkConfigurationFile($file) |
|
| 115 | - { |
|
| 116 | - if (!file_exists($file)) { |
|
| 117 | - throw new \RuntimeException("The requested phpunit configuration was not found at $file"); |
|
| 118 | - } |
|
| 107 | + /** |
|
| 108 | + * check the given file |
|
| 109 | + * |
|
| 110 | + * @param string $file file to check |
|
| 111 | + * @return string returns the file if it is valid |
|
| 112 | + * @throws FileNotFoundException if the file is not found |
|
| 113 | + */ |
|
| 114 | + private static function checkConfigurationFile($file) |
|
| 115 | + { |
|
| 116 | + if (!file_exists($file)) { |
|
| 117 | + throw new \RuntimeException("The requested phpunit configuration was not found at $file"); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - return $file; |
|
| 121 | - } |
|
| 120 | + return $file; |
|
| 121 | + } |
|
| 122 | 122 | } |
@@ -10,9 +10,9 @@ |
||
| 10 | 10 | |
| 11 | 11 | class CIPHPUnitTestRequest |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @var TestCase |
|
| 15 | - */ |
|
| 13 | + /** |
|
| 14 | + * @var TestCase |
|
| 15 | + */ |
|
| 16 | 16 | protected $testCase; |
| 17 | 17 | |
| 18 | 18 | /** |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | if (! defined('TESTPATH')) { |
| 24 | 24 | define('TESTPATH', APPPATH.'tests'.DIRECTORY_SEPARATOR); |
| 25 | 25 | } |
| 26 | - // Current Bootstrap.php should define this, but in case it doesn't: |
|
| 26 | + // Current Bootstrap.php should define this, but in case it doesn't: |
|
| 27 | 27 | if (! defined('CI_PHPUNIT_TESTPATH')) { |
| 28 | 28 | define('CI_PHPUNIT_TESTPATH', dirname(__FILE__).DIRECTORY_SEPARATOR); |
| 29 | 29 | } |
@@ -10,200 +10,200 @@ |
||
| 10 | 10 | |
| 11 | 11 | class Installer |
| 12 | 12 | { |
| 13 | - private $silent = false; |
|
| 14 | - private $app_dir = 'application'; |
|
| 15 | - private $pub_dir = 'public'; |
|
| 16 | - private $test_dir = 'tests'; |
|
| 17 | - private $from_composer = false; |
|
| 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 | - case '--from-composer': |
|
| 64 | - $this->from_composer = true; |
|
| 65 | - $i++; |
|
| 66 | - break; |
|
| 67 | - |
|
| 68 | - default: |
|
| 69 | - throw new Exception('Unknown argument: '.$argv[$i]); |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - public function install() |
|
| 75 | - { |
|
| 76 | - $this->recursiveCopy( |
|
| 77 | - dirname(dirname(__FILE__)).'/application/tests', |
|
| 78 | - $this->app_dir.'/'.$this->test_dir |
|
| 79 | - ); |
|
| 80 | - $this->fixPath(); |
|
| 81 | - if ($this->from_composer) { |
|
| 82 | - $this->recursiveUnlink($this->app_dir.'/'.$this->test_dir.'/_ci_phpunit_test'); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Fix paths in Bootstrap.php |
|
| 88 | - */ |
|
| 89 | - private function fixPath() |
|
| 90 | - { |
|
| 91 | - $file = $this->app_dir.'/'.$this->test_dir.'/Bootstrap.php'; |
|
| 92 | - $contents = file_get_contents($file); |
|
| 93 | - |
|
| 94 | - if (! file_exists('system')) { |
|
| 95 | - if (file_exists('vendor/codeigniter/framework/system')) { |
|
| 96 | - $contents = str_replace( |
|
| 97 | - '$system_path = \'../../system\';', |
|
| 98 | - '$system_path = \'../../vendor/codeigniter/framework/system\';', |
|
| 99 | - $contents |
|
| 100 | - ); |
|
| 101 | - } else { |
|
| 102 | - throw new Exception('Can\'t find "system" folder.'); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if (! file_exists('index.php')) { |
|
| 107 | - if (file_exists($this->pub_dir.'/index.php')) { |
|
| 108 | - // CodeIgniter 3.0.6 and after |
|
| 109 | - $contents = str_replace( |
|
| 110 | - "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
|
| 111 | - "define('FCPATH', realpath(dirname(__FILE__).'/../../{$this->pub_dir}').DIRECTORY_SEPARATOR);", |
|
| 112 | - $contents |
|
| 113 | - ); |
|
| 114 | - // CodeIgniter 3.0.5 and before |
|
| 115 | - $contents = str_replace( |
|
| 116 | - "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", |
|
| 117 | - "define('FCPATH', realpath(dirname(__FILE__).'/../../{$this->pub_dir}').'/');", |
|
| 118 | - $contents |
|
| 119 | - ); |
|
| 120 | - } elseif (file_exists($this->app_dir.'/public/index.php')) { |
|
| 121 | - // CodeIgniter 3.0.6 and after |
|
| 122 | - $contents = str_replace( |
|
| 123 | - "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
|
| 124 | - "define('FCPATH', realpath(dirname(__FILE__).'/../public').DIRECTORY_SEPARATOR);", |
|
| 125 | - $contents |
|
| 126 | - ); |
|
| 127 | - // CodeIgniter 3.0.5 and before |
|
| 128 | - $contents = str_replace( |
|
| 129 | - "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", |
|
| 130 | - "define('FCPATH', realpath(dirname(__FILE__).'/../public').'/');", |
|
| 131 | - $contents |
|
| 132 | - ); |
|
| 133 | - if ($this->app_dir !== 'application') { |
|
| 134 | - $contents = str_replace( |
|
| 135 | - "\$application_folder = '../../application';", |
|
| 136 | - "\$application_folder = '../../{$this->app_dir}';", |
|
| 137 | - $contents |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - } else { |
|
| 141 | - throw new Exception('Can\'t find "index.php".'); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - file_put_contents($file, $contents); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - public function update() |
|
| 149 | - { |
|
| 150 | - $target_dir = $this->app_dir.'/'.$this->test_dir.'/_ci_phpunit_test'; |
|
| 151 | - $this->recursiveUnlink($target_dir); |
|
| 152 | - $this->recursiveCopy( |
|
| 153 | - dirname(dirname(__FILE__)).'/application/tests/_ci_phpunit_test', |
|
| 154 | - $target_dir |
|
| 155 | - ); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Recursive Copy |
|
| 160 | - * |
|
| 161 | - * @param string $src |
|
| 162 | - * @param string $dst |
|
| 163 | - */ |
|
| 164 | - private function recursiveCopy($src, $dst) |
|
| 165 | - { |
|
| 166 | - @mkdir($dst, 0755); |
|
| 167 | - |
|
| 168 | - $iterator = new \RecursiveIteratorIterator( |
|
| 169 | - new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS), |
|
| 170 | - \RecursiveIteratorIterator::SELF_FIRST |
|
| 171 | - ); |
|
| 172 | - |
|
| 173 | - foreach ($iterator as $file) { |
|
| 174 | - if ($file->isDir()) { |
|
| 175 | - @mkdir($dst.'/'.$iterator->getSubPathName()); |
|
| 176 | - } else { |
|
| 177 | - $success = copy($file, $dst.'/'.$iterator->getSubPathName()); |
|
| 178 | - if ($success) { |
|
| 179 | - if (! $this->silent) { |
|
| 180 | - echo 'copied: '.$dst.'/'.$iterator->getSubPathName().PHP_EOL; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Recursive Unlink |
|
| 189 | - * |
|
| 190 | - * @param string $dir |
|
| 191 | - */ |
|
| 192 | - private function recursiveUnlink($dir) |
|
| 193 | - { |
|
| 194 | - $iterator = new \RecursiveIteratorIterator( |
|
| 195 | - new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS), |
|
| 196 | - \RecursiveIteratorIterator::CHILD_FIRST |
|
| 197 | - ); |
|
| 198 | - |
|
| 199 | - foreach ($iterator as $file) { |
|
| 200 | - if ($file->isDir()) { |
|
| 201 | - rmdir($file); |
|
| 202 | - } else { |
|
| 203 | - unlink($file); |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - rmdir($dir); |
|
| 208 | - } |
|
| 13 | + private $silent = false; |
|
| 14 | + private $app_dir = 'application'; |
|
| 15 | + private $pub_dir = 'public'; |
|
| 16 | + private $test_dir = 'tests'; |
|
| 17 | + private $from_composer = false; |
|
| 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 | + case '--from-composer': |
|
| 64 | + $this->from_composer = true; |
|
| 65 | + $i++; |
|
| 66 | + break; |
|
| 67 | + |
|
| 68 | + default: |
|
| 69 | + throw new Exception('Unknown argument: '.$argv[$i]); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + public function install() |
|
| 75 | + { |
|
| 76 | + $this->recursiveCopy( |
|
| 77 | + dirname(dirname(__FILE__)).'/application/tests', |
|
| 78 | + $this->app_dir.'/'.$this->test_dir |
|
| 79 | + ); |
|
| 80 | + $this->fixPath(); |
|
| 81 | + if ($this->from_composer) { |
|
| 82 | + $this->recursiveUnlink($this->app_dir.'/'.$this->test_dir.'/_ci_phpunit_test'); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Fix paths in Bootstrap.php |
|
| 88 | + */ |
|
| 89 | + private function fixPath() |
|
| 90 | + { |
|
| 91 | + $file = $this->app_dir.'/'.$this->test_dir.'/Bootstrap.php'; |
|
| 92 | + $contents = file_get_contents($file); |
|
| 93 | + |
|
| 94 | + if (! file_exists('system')) { |
|
| 95 | + if (file_exists('vendor/codeigniter/framework/system')) { |
|
| 96 | + $contents = str_replace( |
|
| 97 | + '$system_path = \'../../system\';', |
|
| 98 | + '$system_path = \'../../vendor/codeigniter/framework/system\';', |
|
| 99 | + $contents |
|
| 100 | + ); |
|
| 101 | + } else { |
|
| 102 | + throw new Exception('Can\'t find "system" folder.'); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if (! file_exists('index.php')) { |
|
| 107 | + if (file_exists($this->pub_dir.'/index.php')) { |
|
| 108 | + // CodeIgniter 3.0.6 and after |
|
| 109 | + $contents = str_replace( |
|
| 110 | + "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
|
| 111 | + "define('FCPATH', realpath(dirname(__FILE__).'/../../{$this->pub_dir}').DIRECTORY_SEPARATOR);", |
|
| 112 | + $contents |
|
| 113 | + ); |
|
| 114 | + // CodeIgniter 3.0.5 and before |
|
| 115 | + $contents = str_replace( |
|
| 116 | + "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", |
|
| 117 | + "define('FCPATH', realpath(dirname(__FILE__).'/../../{$this->pub_dir}').'/');", |
|
| 118 | + $contents |
|
| 119 | + ); |
|
| 120 | + } elseif (file_exists($this->app_dir.'/public/index.php')) { |
|
| 121 | + // CodeIgniter 3.0.6 and after |
|
| 122 | + $contents = str_replace( |
|
| 123 | + "define('FCPATH', realpath(dirname(__FILE__).'/../..').DIRECTORY_SEPARATOR);", |
|
| 124 | + "define('FCPATH', realpath(dirname(__FILE__).'/../public').DIRECTORY_SEPARATOR);", |
|
| 125 | + $contents |
|
| 126 | + ); |
|
| 127 | + // CodeIgniter 3.0.5 and before |
|
| 128 | + $contents = str_replace( |
|
| 129 | + "define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');", |
|
| 130 | + "define('FCPATH', realpath(dirname(__FILE__).'/../public').'/');", |
|
| 131 | + $contents |
|
| 132 | + ); |
|
| 133 | + if ($this->app_dir !== 'application') { |
|
| 134 | + $contents = str_replace( |
|
| 135 | + "\$application_folder = '../../application';", |
|
| 136 | + "\$application_folder = '../../{$this->app_dir}';", |
|
| 137 | + $contents |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + } else { |
|
| 141 | + throw new Exception('Can\'t find "index.php".'); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + file_put_contents($file, $contents); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + public function update() |
|
| 149 | + { |
|
| 150 | + $target_dir = $this->app_dir.'/'.$this->test_dir.'/_ci_phpunit_test'; |
|
| 151 | + $this->recursiveUnlink($target_dir); |
|
| 152 | + $this->recursiveCopy( |
|
| 153 | + dirname(dirname(__FILE__)).'/application/tests/_ci_phpunit_test', |
|
| 154 | + $target_dir |
|
| 155 | + ); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Recursive Copy |
|
| 160 | + * |
|
| 161 | + * @param string $src |
|
| 162 | + * @param string $dst |
|
| 163 | + */ |
|
| 164 | + private function recursiveCopy($src, $dst) |
|
| 165 | + { |
|
| 166 | + @mkdir($dst, 0755); |
|
| 167 | + |
|
| 168 | + $iterator = new \RecursiveIteratorIterator( |
|
| 169 | + new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS), |
|
| 170 | + \RecursiveIteratorIterator::SELF_FIRST |
|
| 171 | + ); |
|
| 172 | + |
|
| 173 | + foreach ($iterator as $file) { |
|
| 174 | + if ($file->isDir()) { |
|
| 175 | + @mkdir($dst.'/'.$iterator->getSubPathName()); |
|
| 176 | + } else { |
|
| 177 | + $success = copy($file, $dst.'/'.$iterator->getSubPathName()); |
|
| 178 | + if ($success) { |
|
| 179 | + if (! $this->silent) { |
|
| 180 | + echo 'copied: '.$dst.'/'.$iterator->getSubPathName().PHP_EOL; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Recursive Unlink |
|
| 189 | + * |
|
| 190 | + * @param string $dir |
|
| 191 | + */ |
|
| 192 | + private function recursiveUnlink($dir) |
|
| 193 | + { |
|
| 194 | + $iterator = new \RecursiveIteratorIterator( |
|
| 195 | + new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS), |
|
| 196 | + \RecursiveIteratorIterator::CHILD_FIRST |
|
| 197 | + ); |
|
| 198 | + |
|
| 199 | + foreach ($iterator as $file) { |
|
| 200 | + if ($file->isDir()) { |
|
| 201 | + rmdir($file); |
|
| 202 | + } else { |
|
| 203 | + unlink($file); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + rmdir($dir); |
|
| 208 | + } |
|
| 209 | 209 | } |