您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

学习Laravel - 测试代码模板

2024/6/11 15:02:52发布16次查看
学习laravel - 测试代码模板
<?php namespace app\http\controllers; /** * 学习 laravel 的测试用例 * @link http://laravel.com/docs/5.0 * @author yanming <ym@mkjump.com> * * @tutorial * #0, 执行 test/index方法 生成storage/app/route.txt, 添加route.txt内容到app/http/routes.php * #1, 进入项目目录, 执行 php artisan route:cache (clear,list), 缓存route */ use db; use storage; use illuminate\http\request; class testcontroller extends controller { const newline = "\n"; private $route = null; // 生成route的临时变量 /** * create a new controller instance. * * @return void */ public function __construct() { } /** * 反射生成一个route列表 * @example * 测试全部 * test/index * 测试单个例子 * test/methodname */ public function index($methodname=null) { echo "hello, lavavel - self learning!".self::newline; echo "测试开始".self::newline; if (!is_null($methodname) && method_exists(new self(), $methodname)) { echo sprintf("测试 %s", $methodname).self::newline; $this->$methodname(); } else { foreach ($this->getmethod() as $k => $method) { echo sprintf("测试 %d - %s %s", $k, $method, self::newline); //$this->route .= sprintf("route::get('test/%s', 'testcontroller@%s')->where(['%s' => '[a-z]+']);", $method, $method, $method).self::newline; // 调用方法 $this->$method(); } } // 生成route //storage::disk('local')->put('route.txt', $this->route); } /** * 反射获取 *test 方法 */ private function getmethod() { $methods = []; $reflector = new \reflectionclass(new self()); foreach ($reflector->getmethods() as $methodobj) { if (strpos($methodobj->name, "test") > 0) $methods[] = $methodobj->name; } return $methods; } /** * the basics testing */ public function routetest(){} public function middlewaretest(){} public function controllertest(){} public function requesttest(){} public function responsetest(){} public function viewtest(){} /** * architecture foundations testing */ public function serviceprovidetest(){} public function servicecontainertest(){} public function contractstest(){} public function facadestest(){} public function requestlifecircletest(){} public function applicationstructuretest(){} /** * service testing */ public function cachetest() {} public function collectiontest() {} public function commandbustest(){} public function coreextensiontest(){} public function elixirtest(){} public function encryptiontest(){} public function envoytest(){} public function errortest(){} public function logtest(){} public function eventstest(){} public function filesystemtest(){} public function hashingtest(){} public function helptest(){} public function localizationtest(){} public function mailtest(){} public function packagetest(){} public function paginationtest(){} public function queuetest(){} public function sessiontest(){} public function templatetest(){} public function unittesting() {} public function validationtest(){} /** * database testing */ public function basicquerytest(){} public function querybuildtest(){} public function eloquenttest(){} public function schemabuildertest(){} public function migrationtest(){} public function seedtest(){} public function redistest(){} /** * cli testing */ public function clitest(){echo 'cli';} }
2. [代码]添加到 app/http/routes.php
route::get('test/index/{methodname?}', 'testcontroller@index')->where(['methodname' => '[a-z]+']);
3. [代码]storage/app/route.txt
route::get('test/routetest', 'testcontroller@routetest')->where(['routetest' => '[a-z]+']); route::get('test/middlewaretest', 'testcontroller@middlewaretest')->where(['middlewaretest' => '[a-z]+']); route::get('test/controllertest', 'testcontroller@controllertest')->where(['controllertest' => '[a-z]+']); route::get('test/requesttest', 'testcontroller@requesttest')->where(['requesttest' => '[a-z]+']); route::get('test/responsetest', 'testcontroller@responsetest')->where(['responsetest' => '[a-z]+']); route::get('test/viewtest', 'testcontroller@viewtest')->where(['viewtest' => '[a-z]+']); route::get('test/serviceprovidetest', 'testcontroller@serviceprovidetest')->where(['serviceprovidetest' => '[a-z]+']); route::get('test/servicecontainertest', 'testcontroller@servicecontainertest')->where(['servicecontainertest' => '[a-z]+']); route::get('test/contractstest', 'testcontroller@contractstest')->where(['contractstest' => '[a-z]+']); route::get('test/facadestest', 'testcontroller@facadestest')->where(['facadestest' => '[a-z]+']); route::get('test/requestlifecircletest', 'testcontroller@requestlifecircletest')->where(['requestlifecircletest' => '[a-z]+']); route::get('test/applicationstructuretest', 'testcontroller@applicationstructuretest')->where(['applicationstructuretest' => '[a-z]+']); route::get('test/cachetest', 'testcontroller@cachetest')->where(['cachetest' => '[a-z]+']); route::get('test/collectiontest', 'testcontroller@collectiontest')->where(['collectiontest' => '[a-z]+']); route::get('test/commandbustest', 'testcontroller@commandbustest')->where(['commandbustest' => '[a-z]+']); route::get('test/coreextensiontest', 'testcontroller@coreextensiontest')->where(['coreextensiontest' => '[a-z]+']); route::get('test/elixirtest', 'testcontroller@elixirtest')->where(['elixirtest' => '[a-z]+']); route::get('test/encryptiontest', 'testcontroller@encryptiontest')->where(['encryptiontest' => '[a-z]+']); route::get('test/envoytest', 'testcontroller@envoytest')->where(['envoytest' => '[a-z]+']); route::get('test/errortest', 'testcontroller@errortest')->where(['errortest' => '[a-z]+']); route::get('test/logtest', 'testcontroller@logtest')->where(['logtest' => '[a-z]+']); route::get('test/eventstest', 'testcontroller@eventstest')->where(['eventstest' => '[a-z]+']); route::get('test/filesystemtest', 'testcontroller@filesystemtest')->where(['filesystemtest' => '[a-z]+']); route::get('test/hashingtest', 'testcontroller@hashingtest')->where(['hashingtest' => '[a-z]+']); route::get('test/helptest', 'testcontroller@helptest')->where(['helptest' => '[a-z]+']); route::get('test/localizationtest', 'testcontroller@localizationtest')->where(['localizationtest' => '[a-z]+']); route::get('test/mailtest', 'testcontroller@mailtest')->where(['mailtest' => '[a-z]+']); route::get('test/packagetest', 'testcontroller@packagetest')->where(['packagetest' => '[a-z]+']); route::get('test/paginationtest', 'testcontroller@paginationtest')->where(['paginationtest' => '[a-z]+']); route::get('test/queuetest', 'testcontroller@queuetest')->where(['queuetest' => '[a-z]+']); route::get('test/sessiontest', 'testcontroller@sessiontest')->where(['sessiontest' => '[a-z]+']); route::get('test/templatetest', 'testcontroller@templatetest')->where(['templatetest' => '[a-z]+']); route::get('test/unittesting', 'testcontroller@unittesting')->where(['unittesting' => '[a-z]+']); route::get('test/validationtest', 'testcontroller@validationtest')->where(['validationtest' => '[a-z]+']); route::get('test/basicquerytest', 'testcontroller@basicquerytest')->where(['basicquerytest' => '[a-z]+']); route::get('test/querybuildtest', 'testcontroller@querybuildtest')->where(['querybuildtest' => '[a-z]+']); route::get('test/eloquenttest', 'testcontroller@eloquenttest')->where(['eloquenttest' => '[a-z]+']); route::get('test/schemabuildertest', 'testcontroller@schemabuildertest')->where(['schemabuildertest' => '[a-z]+']); route::get('test/migrationtest', 'testcontroller@migrationtest')->where(['migrationtest' => '[a-z]+']); route::get('test/seedtest', 'testcontroller@seedtest')->where(['seedtest' => '[a-z]+']); route::get('test/redistest', 'testcontroller@redistest')->where(['redistest' => '[a-z]+']); route::get('test/clitest', 'testcontroller@clitest')->where(['clitest' => '[a-z]+']);
以上就是学习laravel - 测试代码模板的内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product