> php教程 > php手册 > 본문

学习Laravel

WBOY
풀어 주다: 2016-06-06 19:38:28
원래의
1366명이 탐색했습니다.

无详细内容 无 ?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/ht

<?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';}
}
로그인 후 복사
Route::get('test/index/{methodName?}', 'TestController@index')->where(['methodName' => '[a-z]+']);
로그인 후 복사
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]+']);
로그인 후 복사
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!