<?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)!

本篇文章给大家带来了关于laravel的相关知识,其中主要介绍了关于单点登录的相关问题,单点登录是指在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于laravel的相关知识,其中主要介绍了关于Laravel的生命周期相关问题,Laravel 的生命周期从public\index.php开始,从public\index.php结束,希望对大家有帮助。

在laravel中,guard是一个用于用户认证的插件;guard的作用就是处理认证判断每一个请求,从数据库中读取数据和用户输入的对比,调用是否登录过或者允许通过的,并且Guard能非常灵活的构建一套自己的认证体系。

laravel中asset()方法的用法:1、用于引入静态文件,语法为“src="{{asset(‘需要引入的文件路径’)}}"”;2、用于给当前请求的scheme前端资源生成一个url,语法为“$url = asset('前端资源')”。

本篇文章给大家带来了关于laravel的相关知识,其中主要介绍了关于使用中间件记录用户请求日志的相关问题,包括了创建中间件、注册中间件、记录用户访问等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于laravel的相关知识,其中主要介绍了关于中间件的相关问题,包括了什么是中间件、自定义中间件等等,中间件为过滤进入应用的 HTTP 请求提供了一套便利的机制,下面一起来看一下,希望对大家有帮助。

laravel路由文件在“routes”目录里。Laravel中所有的路由文件定义在routes目录下,它里面的内容会自动被框架加载;该目录下默认有四个路由文件用于给不同的入口使用:web.php、api.php、console.php等。

在laravel中,scope用于处理模型中的数据,在模型中可以定义scope开头方法,这类方法可以通过模型直接调用,被称为查询作用域,语法为“public function scope首字母大写单词($query){...}”。


핫 AI 도구

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

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

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

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

WebStorm Mac 버전
유용한 JavaScript 개발 도구

Dreamweaver Mac版
시각적 웹 개발 도구

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

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

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

뜨거운 주제



