学习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 - 测试代码模板的内容,更多相关内容请关注PHP中文网(www.php.cn)!

핫 AI 도구

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

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

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

Clothoff.io
AI 옷 제거제

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

인기 기사

뜨거운 도구

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

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

Laravel은 웹 응용 프로그램을 쉽게 구축하기위한 PHP 프레임 워크입니다. 설치 : Composer를 사용하여 전 세계적으로 Laravel CLI를 설치하고 프로젝트 디렉토리에서 응용 프로그램을 작성하는 등 다양한 기능을 제공합니다. 라우팅 : Routes/Web.php에서 URL과 핸들러 간의 관계를 정의하십시오. 보기 : 리소스/뷰에서보기를 작성하여 응용 프로그램의 인터페이스를 렌더링합니다. 데이터베이스 통합 : MySQL과 같은 데이터베이스와 상자 외 통합을 제공하고 마이그레이션을 사용하여 테이블을 작성하고 수정합니다. 모델 및 컨트롤러 : 모델은 데이터베이스 엔티티를 나타내고 컨트롤러는 HTTP 요청을 처리합니다.

CRAFTCMS를 사용하여 웹 사이트를 개발할 때 특히 CSS 및 JavaScript 파일을 자주 업데이트 할 때 자주 리소스 파일 캐싱 문제가 발생하면 이전 버전의 파일이 여전히 브라우저에서 캐싱 될 수 있으므로 사용자는 최신 변경 사항을 볼 수 없습니다. 이 문제는 사용자 경험에 영향을 줄뿐만 아니라 개발 및 디버깅의 어려움을 증가시킵니다. 최근에 나는 프로젝트에서 비슷한 문제를 겪었고, 약간의 탐색 후 플러그인 Wiejeben/Craft-Laravel-Mix를 발견하여 캐싱 문제를 완벽하게 해결했습니다.

Laravel 프레임 워크를 배우고 싶지만 자원이나 경제적 압력이 없습니까? 이 기사는 Laravel의 무료 학습을 제공하며 온라인 플랫폼, 문서 및 커뮤니티 포럼과 같은 리소스를 사용하여 PHP 개발 여정을 시작하는 것에서 마스터까지의 탄탄한 토대를 마련하는 방법을 가르쳐줍니다.

기사 요약 :이 기사는 Laravel 프레임 워크를 쉽게 설치하는 방법에 대한 독자들을 안내하기위한 자세한 단계별 지침을 제공합니다. Laravel은 웹 애플리케이션의 개발 프로세스를 가속화하는 강력한 PHP 프레임 워크입니다. 이 자습서는 시스템 요구 사항에서 데이터베이스 구성 및 라우팅 설정에 이르기까지 설치 프로세스를 다룹니다. 이러한 단계를 수행함으로써 독자들은 라벨 프로젝트를위한 탄탄한 토대를 빠르고 효율적으로 놓을 수 있습니다.

초보자를위한 Laravel Framework 버전 선택 안내서 에서이 기사는 초보자가 많은 버전 중에서 정보에 입각 한 선택을하는 데 도움이되도록 설계된 Laravel의 버전 차이점으로 뛰어 들었습니다. 우리는 각 릴리스의 주요 기능에 중점을두고 장단점을 비교하며 초보자가 기술 수준 및 프로젝트 요구 사항에 따라 가장 적합한 Laravel 버전을 선택할 수 있도록 유용한 조언을 제공 할 것입니다. 초보자에게는 적절한 버전의 Laravel을 선택하는 것이 학습 곡선과 전반적인 개발 경험에 크게 영향을 줄 수 있기 때문에 중요합니다.

Laravel provides a comprehensive Auth framework for implementing user login functions, including: Defining user models (Eloquent model), creating login forms (Blade template engine), writing login controllers (inheriting Auth\LoginController), verifying login requests (Auth::attempt) Redirecting after login is successful (redirect) considering security factors: hash passwords, anti-CSRF protection, rate limiting and security 헤더. 또한 Auth Framework는 비밀번호 재설정, 이메일 등록 및 확인과 같은 기능도 제공합니다. 자세한 내용은 Laravel 문서를 참조하십시오 : https://laravel.com/doc

Laravel 프레임 워크에는 개발자의 다양한 요구를 충족시키기 위해 버전 번호를 쉽게 볼 수있는 내장 방법이 있습니다. 이 기사는 Composer Command Line 도구 사용, .env 파일에 액세스하거나 PHP 코드를 통해 버전 정보를 얻는 것을 포함하여 이러한 방법을 탐색합니다. 이러한 방법은 Laravel 애플리케이션의 버전 관리를 유지 관리하고 관리하는 데 필수적입니다.

Laravel과 ThinkPHP는 모두 인기있는 PHP 프레임 워크이며 개발에 고유 한 장점과 단점이 있습니다. 이 기사는 두 가지 깊이를 비교하여 건축, 기능 및 성능 차이를 강조하여 개발자가 특정 프로젝트 요구에 따라 정보에 입각 한 선택을 할 수 있도록 도와줍니다.
