public function __construct($app_path = null, $think_path = null, $runtime_path = null)
{
$const = $this->guessPath();
if ($app_path === null) {
$app_path = $const['APP_PATH'];
}
if ($think_path === null) {
$think_path = $const['THINK_PATH'];
}
if ($runtime_path === null) {
$runtime_path = $const['ROOT_PATH'] . '/Runtime-test';
}
if (!file_exists($app_path)) {
throw new \RuntimeException($app_path . '不存在');
}
if (!file_exists($think_path)) {
throw new \RuntimeException($think_path . '不存在');
}
if (!file_exists($runtime_path)) {
$bool = mkdir($runtime_path);
if (!$bool) {
throw new \RuntimeException($runtime_path . '创建失败');
}
} else {
if (!is_writable($runtime_path)) {
throw new \RuntimeException($runtime_path . '不可写');
}
}
/**
* 单元测试,会出现变量重复定义错误,使用defined来判断
*/
defined('APP_DEBUG') or define('APP_DEBUG', true);
defined('APP_PATH') or define('APP_PATH', rtrim($app_path, '\\/') . '/');
defined('RUNTIME_PATH') or define('RUNTIME_PATH', rtrim($runtime_path, '\\/') . '/');
defined('THINK_PATH') or define('THINK_PATH', rtrim($think_path, '\\/') . '/');
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['REMOTE_PORT'] = '32800';
$_SERVER['SERVER_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
$_SERVER['HTTP_REFERER'] = '/';
$this->_defineConsts();
}