ホームページ php教程 PHP源码 学习Laravel - 测试代码模板

学习Laravel - 测试代码模板

May 23, 2016 pm 05:10 PM

学习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(&#39;test/%s&#39;, &#39;TestController@%s&#39;)->where([&#39;%s&#39; => &#39;[a-z]+&#39;]);", 
          $method, $method, $method).self::NEWLINE;
                // 调用方法
                $this->$method();    
            }   
        }       
        // 生成route  
        //Storage::disk(&#39;local&#39;)->put(&#39;route.txt&#39;, $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 &#39;cli&#39;;}
}
ログイン後にコピー

2. [代码]添加到 app/Http/routes.php

Route::get(&#39;test/index/{methodName?}&#39;, &#39;TestController@index&#39;)->where([&#39;methodName&#39; => &#39;[a-z]+&#39;]);
ログイン後にコピー

3. [代码]storage/app/route.txt

Route::get(&#39;test/routeTest&#39;, &#39;TestController@routeTest&#39;)->where([&#39;routeTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/middlewareTest&#39;, &#39;TestController@middlewareTest&#39;)->where([&#39;middlewareTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/controllerTest&#39;, &#39;TestController@controllerTest&#39;)->where([&#39;controllerTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/requestTest&#39;, &#39;TestController@requestTest&#39;)->where([&#39;requestTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/responseTest&#39;, &#39;TestController@responseTest&#39;)->where([&#39;responseTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/viewTest&#39;, &#39;TestController@viewTest&#39;)->where([&#39;viewTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/serviceProvideTest&#39;, &#39;TestController@serviceProvideTest&#39;)->where([&#39;serviceProvideTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/serviceContainerTest&#39;, &#39;TestController@serviceContainerTest&#39;)->where([&#39;serviceContainerTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/contractsTest&#39;, &#39;TestController@contractsTest&#39;)->where([&#39;contractsTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/facadesTest&#39;, &#39;TestController@facadesTest&#39;)->where([&#39;facadesTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/requestLifeCircleTest&#39;, &#39;TestController@requestLifeCircleTest&#39;)->where([&#39;requestLifeCircleTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/applicationStructureTest&#39;, &#39;TestController@applicationStructureTest&#39;)->where([&#39;applicationStructureTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/cacheTest&#39;, &#39;TestController@cacheTest&#39;)->where([&#39;cacheTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/collectionTest&#39;, &#39;TestController@collectionTest&#39;)->where([&#39;collectionTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/commandBusTest&#39;, &#39;TestController@commandBusTest&#39;)->where([&#39;commandBusTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/coreExtensionTest&#39;, &#39;TestController@coreExtensionTest&#39;)->where([&#39;coreExtensionTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/elixirTest&#39;, &#39;TestController@elixirTest&#39;)->where([&#39;elixirTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/encryptionTest&#39;, &#39;TestController@encryptionTest&#39;)->where([&#39;encryptionTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/envoyTest&#39;, &#39;TestController@envoyTest&#39;)->where([&#39;envoyTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/errorTest&#39;, &#39;TestController@errorTest&#39;)->where([&#39;errorTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/logTest&#39;, &#39;TestController@logTest&#39;)->where([&#39;logTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/eventsTest&#39;, &#39;TestController@eventsTest&#39;)->where([&#39;eventsTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/filesystemTest&#39;, &#39;TestController@filesystemTest&#39;)->where([&#39;filesystemTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/hashingTest&#39;, &#39;TestController@hashingTest&#39;)->where([&#39;hashingTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/helpTest&#39;, &#39;TestController@helpTest&#39;)->where([&#39;helpTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/localizationTest&#39;, &#39;TestController@localizationTest&#39;)->where([&#39;localizationTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/mailTest&#39;, &#39;TestController@mailTest&#39;)->where([&#39;mailTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/packageTest&#39;, &#39;TestController@packageTest&#39;)->where([&#39;packageTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/paginationTest&#39;, &#39;TestController@paginationTest&#39;)->where([&#39;paginationTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/queueTest&#39;, &#39;TestController@queueTest&#39;)->where([&#39;queueTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/sessionTest&#39;, &#39;TestController@sessionTest&#39;)->where([&#39;sessionTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/templateTest&#39;, &#39;TestController@templateTest&#39;)->where([&#39;templateTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/unitTesting&#39;, &#39;TestController@unitTesting&#39;)->where([&#39;unitTesting&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/validationTest&#39;, &#39;TestController@validationTest&#39;)->where([&#39;validationTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/basicQueryTest&#39;, &#39;TestController@basicQueryTest&#39;)->where([&#39;basicQueryTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/queryBuildTest&#39;, &#39;TestController@queryBuildTest&#39;)->where([&#39;queryBuildTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/eloquentTest&#39;, &#39;TestController@eloquentTest&#39;)->where([&#39;eloquentTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/schemaBuilderTest&#39;, &#39;TestController@schemaBuilderTest&#39;)->where([&#39;schemaBuilderTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/migrationTest&#39;, &#39;TestController@migrationTest&#39;)->where([&#39;migrationTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/seedTest&#39;, &#39;TestController@seedTest&#39;)->where([&#39;seedTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/redisTest&#39;, &#39;TestController@redisTest&#39;)->where([&#39;redisTest&#39; => &#39;[a-z]+&#39;]);
Route::get(&#39;test/cliTest&#39;, &#39;TestController@cliTest&#39;)->where([&#39;cliTest&#39; => &#39;[a-z]+&#39;]);
ログイン後にコピー

           

 以上就是学习Laravel - 测试代码模板的内容,更多相关内容请关注PHP中文网(www.php.cn)!

       

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

Laravel - アーティザンコマンド Laravel - アーティザンコマンド Aug 27, 2024 am 10:51 AM

Laravel - アーティザン コマンド - Laravel 5.7 には、新しいコマンドを処理およびテストするための新しい方法が付属しています。これには職人コマンドをテストする新しい機能が含まれており、そのデモについては以下で説明します。

Laravel と CodeIgniter の最新バージョンの比較 Laravel と CodeIgniter の最新バージョンの比較 Jun 05, 2024 pm 05:29 PM

Laravel 9 と CodeIgniter 4 の最新バージョンでは、更新された機能と改善が提供されます。 Laravel9はMVCアーキテクチャを採用しており、データベース移行、認証、テンプレートエンジンなどの機能を提供します。 CodeIgniter4 は、HMVC アーキテクチャを使用してルーティング、ORM、およびキャッシュを提供します。パフォーマンスの面では、Laravel9 のサービスプロバイダーベースの設計パターンと CodeIgniter4 の軽量フレームワークにより、優れたパフォーマンスが得られます。実際のアプリケーションでは、Laravel9 は柔軟性と強力な機能を必要とする複雑なプロジェクトに適しており、CodeIgniter4 は迅速な開発や小規模なアプリケーションに適しています。

Laravel と CodeIgniter のデータ処理機能はどのように比較されますか? Laravel と CodeIgniter のデータ処理機能はどのように比較されますか? Jun 01, 2024 pm 01:34 PM

Laravel と CodeIgniter のデータ処理機能を比較します。 ORM: Laravel はクラスとオブジェクトのリレーショナル マッピングを提供する EloquentORM を使用しますが、CodeIgniter は ActiveRecord を使用してデータベース モデルを PHP クラスのサブクラスとして表します。クエリビルダー: Laravel には柔軟なチェーンクエリ API がありますが、CodeIgniter のクエリビルダーはよりシンプルで配列ベースです。データ検証: Laravel はカスタム検証ルールをサポートする Validator クラスを提供しますが、CodeIgniter には組み込みの検証関数が少なく、カスタム ルールの手動コーディングが必要です。実践例:ユーザー登録例はLarを示しています

Laravel と CodeIgniter: 大規模プロジェクトにはどちらのフレームワークが適していますか? Laravel と CodeIgniter: 大規模プロジェクトにはどちらのフレームワークが適していますか? Jun 04, 2024 am 09:09 AM

大規模プロジェクト用のフレームワークを選択する場合、Laravel と CodeIgniter にはそれぞれ独自の利点があります。 Laravel はエンタープライズレベルのアプリケーション向けに設計されており、モジュール設計、依存関係の注入、強力な機能セットを提供します。 CodeIgniter は、速度と使いやすさを重視した、小規模から中規模のプロジェクトに適した軽量フレームワークです。複雑な要件と多数のユーザーを伴う大規模なプロジェクトには、Laravel のパワーとスケーラビリティがより適しています。単純なプロジェクトやリソースが限られている状況では、CodeIgniter の軽量で迅速な開発機能がより理想的です。

Laravel と CodeIgniter ではどちらのテンプレート エンジンが優れていますか? Laravel と CodeIgniter ではどちらのテンプレート エンジンが優れていますか? Jun 03, 2024 am 11:30 AM

Laravel の Blade と CodeIgniter の Twig テンプレート エンジンを比較し、プロジェクトのニーズと個人的な好みに基づいて選択してください。Blade は MVC 構文に基づいており、適切なコード編成とテンプレートの継承を促進します。 Twig は、柔軟な構文、強力なフィルター、拡張サポート、セキュリティ サンドボックスを提供するサードパーティ ライブラリです。

Laravel と CodeIgniter ではどちらが初心者に優しいでしょうか? Laravel と CodeIgniter ではどちらが初心者に優しいでしょうか? Jun 05, 2024 pm 07:50 PM

初心者にとって、CodeIgniter は学習曲線が緩やかで機能は少ないですが、基本的なニーズはカバーしています。 Laravel は幅広い機能セットを提供しますが、学習曲線はわずかに急になります。パフォーマンスの点では、Laravel と CodeIgniter はどちらも良好なパフォーマンスを示します。 Laravel にはより広範なドキュメントとアクティブなコミュニティ サポートがあり、CodeIgniter はよりシンプルで軽量で、強力なセキュリティ機能を備えています。ブログアプリケーションを構築する実際のケースでは、Laravel の EloquentORM を使用するとデータ操作が簡素化されますが、CodeIgniter ではより手動の構成が必要になります。

C++ テンプレートとジェネリックの比較? C++ テンプレートとジェネリックの比較? Jun 04, 2024 pm 04:24 PM

C++ におけるテンプレートとジェネリックの違い: テンプレート: コンパイル時に定義され、明確に型指定され、効率が高く、コード サイズが小さい。ジェネリック: 実行時の型指定、抽象インターフェイス、柔軟性を提供しますが、効率は低くなります。

Laravel と CodeIgniter: 小規模プロジェクトにはどちらのフレームワークが適していますか? Laravel と CodeIgniter: 小規模プロジェクトにはどちらのフレームワークが適していますか? Jun 04, 2024 pm 05:29 PM

小規模なプロジェクトの場合、Laravel は強力な機能とセキュリティを必要とする大規模なプロジェクトに適しています。 CodeIgniter は、軽量さと使いやすさを必要とする非常に小規模なプロジェクトに適しています。

See all articles