<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] ## 概述 tp6 支持支持直接使用 phpunit 的單元測試 安裝 ``` composer require --dev phpunit/phpunit ``` 使用 <details> <summary>/test/DemoTest.php</summary> ``` <?php declare (strict_types=1); namespace tests; final class DemoTest extends \PHPUnit\Framework\TestCase { /** * 這里是測試控制的某個方法產出的結果 * * @test */ public function testControllerDemo(): void { $request = new \app\Request(); $request->setMethod('POST'); // 路由地址 $request->setUrl('/index/home'); //$request->withGet(['xid' => 99,]); //$request->withPost(['aaa' => 111, 'bbb' => 222,]); $request->withHeader(['HTTP_ACCEPT' => 'application/json',]); // 初始化框架,并將請求信息類注入到框架里面 $app = (new \think\App()); $app->http->run($request); // 調用框架方法,這里可以按命名空間直接調用 $userController = new UserController($app); // 請求接口的控制器方法 $response = $userController->index(); // 獲取接口返回得body內容 $content = $response->getContent(); // 可以進行你的斷言操作了 $this->assertEquals("success", $content); } /** * @test */ public function testDemo1(): void { //斷言為真 $this->assertTrue(true); } } ``` </details> <br/> 實際的例子 <details> <summary>/test/DemoTest.php</summary> ``` <?php declare (strict_types=1); namespace tests; use app\admin\controller\v1\Login; use app\common\services\User; use PHPUnit\Framework\TestCase; use think\App; class UserTest extends TestCase{ private $app; protected function setUp(): void{ parent::setUp(); $this->app=new App(); $this->app->http->run(); } /** * 測試service * @return void */ public function testLogin(): void { $user = new User(new \app\common\model\User(),new \app\common\validate\User()); // 測試正常登錄 $res = $user->login("superadmin","123456"); if($res===false){ $this->expectErrorMessage($user->getErr()); } $this->assertEquals("superadmin",$res['login_name']); // 測試異常 $checkData=[ '測試賬號不存在'=>['superadmin1','123456','賬號不存在'], '測試密碼不正確'=>['superadmin','123456','密碼不正確'], '測試站字段為空'=>['','123456','賬號字段為空'], '測試密碼字段為空'=>['superadmin','','密碼字段為空'], ]; foreach($checkData as $item){ $res = $user->login($item[0],$item[1]); if($res===false){ $this->assertEquals($item[2],$user->getErr()); } } } /** * 測試控制器 * @return void */ public function testLoginApi():void{ //由于 functions.php 無法自定自定引入 require_once __DIR__.'/../app/admin/config/functions.php'; $request = new \app\Request(); $request->setMethod('POST'); // 路由地址 $request->setUrl('/v1/admin/login/login'); $request->withPost([ 'login_name'=>'superadmin', 'password'=>'123456', ]); $this->app->http->run($request); $login = new Login($this->app); $service = new User(new \app\common\model\User(), new \app\common\validate\User()); $res = $login->login($service); $resArr =$res->getData(); $this->assertEquals(0,$resArr['code']); $this->assertEquals("登錄成功",$resArr['msg']); $this->assertEquals("superadmin",$resArr['data']['login_name']); } } ``` </details> <br/>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看