<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] ## 概述 編寫代碼來將整個場景設置成某個已知的狀態,并在測試結束后將其復原到初始狀態。這個已知的狀態稱為測試的 基境(fixture) ## 語法 ``` setUp() // 初始化 - 每個測試函數都會調用的 tearDown() // 執行還原 - 不管是否成功,都會執行 setUpBeforeClass() // 只執行一次 - 如數據庫創立連接 tearDownAfterClass() // 只在結束時執行一次 ``` > tearDown() 只有資源數據才需要調用,所以一般是并需要setUp()后,必須調用tearDown() ## 實例 ### hello wold <details> <summary>test.php</summary> ``` <?php use PHPUnit\Framework\TestCase; class LongArrayDiffTest extends TestCase { protected array $stack; public function setUp():void { echo "====start====\n"; $this->stack=[]; } public function tearDown():void { echo "====end====\n"; unset($this->stack); } public static function setUpBeforeClass():void { echo "====setUpBeforeClass====\n"; } public static function tearDownAfterClass():void { echo "====tearDownAfterClass====\n"; } public function testDemo1(){ echo "demo1\n"; $this->stack[]=1; $this->assertEquals([1],$this->stack); } public function testDemo2(){ echo "demo2\n"; $this->stack[]=2; $this->assertEquals([2],$this->stack); } public function testDemo3(){ echo "demo3\n"; $this->stack[]=3; $this->assertEquals([3],$this->stack); } } ``` </details> <br/> 輸出 ``` ====setUpBeforeClass==== ====start==== demo1 ====end==== ====start==== demo2 ====end==== ====start==== demo3 ====end==== ====tearDownAfterClass==== ``` ### 基境共享 <details> <summary>test.php</summary> ``` <?php use PHPUnit\Framework\TestCase; class LongArrayDiffTest extends TestCase { /** * @var false|resource */ protected static $handle; public static function setUpBeforeClass(): void{ self::$handle=fopen('1.txt', 'ab'); } public static function tearDownAfterClass(): void{ fclose(self::$handle); } public function testFile(){ $len = fwrite(self::$handle, 'test'); $this->assertEquals(strlen('test'),$len); } } ``` </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>

                              哎呀哎呀视频在线观看