代码拉取完成,页面将自动刷新
<?php
define('CUR_PATH', dirname(__FILE__));
if ($argc < 3) {
echo "\n";
echo colorfulString("Usage:\n", 'WARNING');
echo "\n";
echo colorfulString("Options:\n", 'WARNING');
echo colorfulString(' file_path', 'NOTE'), " Require. Path to the PHP source code file\n";
echo colorfulString(' class_name', 'NOTE'), " Require. The class name need to be tested\n";
echo colorfulString(' bootstrap', 'NOTE'), " NOT require. Path to the bootsrap file, usually is test_env.php\n";
echo colorfulString(' author', 'NOTE'), " NOT require. Your great name here, default is dogstar\n";
echo "\n";
echo colorfulString("Demo:\n", 'WARNING');
echo " php ./build_test.php ./Demo.php Demo > Demo_Test.php\n";
echo "\n";
echo colorfulString("Tips:\n", 'WARNING');
echo " This will output the code directly, you can save them to test file like with _Test.php suffix.\n";
echo "\n";
die();
}
//var_dump($argv);die;
$filePath = $argv[1];
$className = $argv[2];
$bootstrap = isset($argv[3]) ? $argv[3] : null;
$author = isset($argv[4]) ? $argv[4] : 'dogstar';
$apiPath = str_replace('.php', '', ltrim(ltrim($argv[2], '.'), '/'));
//if (!empty($bootstrap)) {
// require $bootstrap;
//}
//require $filePath;
//if (!class_exists($className)) {
// echo colorfulString("Error: cannot find class($className). \n\n", 'FAILURE');
// die();
//}
//$reflector = new ReflectionClass($className);
//$methods = $reflector->getMethods(ReflectionMethod::IS_PUBLIC);
date_default_timezone_set('Asia/Shanghai');
$objName = lcfirst(str_replace(array('_', '\\'), array('', ''), $className));
$code = "<?php
/**
* PhpUnderControl_" . str_replace('_', '', $className) . "_Test
*
* 针对 $filePath $className 类的PHPUnit单元测试
*
* @author: $author " . date('Ymd') . "
*/
";
if (file_exists(dirname(__FILE__) . '/test_env.php')) {
$code .= "require_once dirname(__FILE__) . '/test_env.php';
";
} else {
$code .= "//require_once dirname(__FILE__) . '/test_env.php';
";
}
echo $code;
echo "\n";
$apiFilePath = CUR_PATH . DIRECTORY_SEPARATOR . $apiPath . '.php';
file_put_contents($apiFilePath, $code);
function colorfulString($text, $type = NULL) {
$colors = array(
'WARNING' => '1;33',
'NOTE' => '1;36',
'SUCCESS' => '1;32',
'FAILURE' => '1;35',
);
if (empty($type) || !isset($colors[$type])){
return $text;
}
return "\033[" . $colors[$type] . "m" . $text . "\033[0m";
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。