Learning Laravel-test code template-PHP source code

Source: Internet
Author: User
Tags reflector
Learning Laravel-test code template Learning Laravel-test code template

 ** @ Tutorial * #0: execute the test/index method to generate storage/app/route.txt, and upload route.txt to app/http/routes. php * #1. go to the project directory and run php artisan route: cache (clear, list), cache route */use DB; use Storage; use Illuminate \ Http \ Request; class TestController extends Controller {const NEWLINE = "\ n"; private $ route = null; // generate a temporary route variable/*** Create a new controller instance. ** @ return void */public function _ construct () {}/*** Reflection generates a route list * @ example * test all * test/index * test a single example * test/methodName */public function index ($ methodName = Null) {echo "Hello, Lavavel-Self Learning! ". Self: NEWLINE; echo" test started ". self: NEWLINE; if (! Is_null ($ methodName) & method_exists (new self (), $ methodName) {echo sprintf ("test % s", $ methodName ). self: NEWLINE; $ this-> $ methodName ();} else {foreach ($ this-> getMethod () as $ k => $ method) {echo sprintf ("test % d-% s", $ k, $ method, self: NEWLINE); // $ this-> route. = sprintf ("Route: get ('test/% s', 'testcontroller @ % S ') -> where (['% s' =>' [a-z] + ']); ", $ method ). self: NEWLINE; // call method $ this-> $ method () ;}// generate route // Storage: disk ('Local')-> put('route.txt ', $ this-> route);}/*** obtain the * Test method */private function getMethod () by reflection {$ 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. [code] add to app/Http/routes. php

Route::get('test/index/{methodName?}', 'TestController@index')->where(['methodName' => '[a-z]+']);

3. [code] 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]+']);

The above is the content of the Laravel-test code template. For more information, see The PHP Chinese website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.