<?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 - 测试代码模板的内容,更多相关内容请关注PHP中文网(www.php.cn)!
성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사
<garden> : 정원 재배 - 완전한 돌연변이 가이드
3 몇 주 전ByDDD
<gum> : Bubble Gum Simulator Infinity- 로얄 키를 얻고 사용하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
KB5055612 수정 방법 Windows 10에 설치되지 않습니까?
3 몇 주 전ByDDD
Nordhold : Fusion System, 설명
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
Mandragora : 마녀 트리의 속삭임 - Grappling Hook 잠금 해제 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.