Ai
2 Star 0 Fork 0

雲溪/php

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test.php 2.51 KB
一键复制 编辑 原始数据 按行查看 历史
雲溪 提交于 2018-06-02 14:53 +08:00 . init first commit
<?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";
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/laravelmall/php.git
git@gitee.com:laravelmall/php.git
laravelmall
php
php
master

搜索帮助