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

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 對 PHP 錯誤進行測試 默認情況下,PHPUnit 將測試在執行中觸發的 PHP 錯誤、警告、通知都轉換為異常。利用這些異常,就可以,比如說,預期測試將觸發 PHP 錯誤,如[Example?2.14, “用 @expectedException 來預期 PHP 錯誤”](# "Example?2.14.?用 @expectedException 來預期 PHP 錯誤")所示。 >[info] ### Note > PHP 的 `error_reporting` 運行時配置會對 PHPUnit 將哪些錯誤轉換為異常有所限制。如果在這個特性上碰到問題,請確認 PHP 的配置中沒有抑制想要測試的錯誤類型。 **Example?2.14.?用 @expectedException 來預期 PHP 錯誤** ~~~ <?php class ExpectedErrorTest extends PHPUnit_Framework_TestCase { /** * @expectedException PHPUnit_Framework_Error */ public function testFailingInclude() { include 'not_existing_file.php'; } } ?> ~~~ ~~~ phpunit -d error_reporting=2 ExpectedErrorTest PHPUnit 5.0.0 by Sebastian Bergmann and contributors. . Time: 0 seconds, Memory: 5.25Mb OK (1 test, 1 assertion) ~~~ `PHPUnit_Framework_Error_Notice` 和 `PHPUnit_Framework_Error_Warning` 分別代表 PHP 通知與 PHP 警告。 >[info] ### Note > 對異常進行測試是越明確越好的。對太籠統的類進行測試有可能導致不良副作用。因此,不再允許用 `@expectedException` 或 `setExpectedException()` 對 `Exception` 類進行測試。 如果測試依靠會觸發錯誤的 PHP 函數,例如 `fopen` ,有時候在測試中使用錯誤抑制符會很有用。通過抑制住錯誤通知,就能對返回值進行檢查,否則錯誤通知將會導致拋出 `PHPUnit_Framework_Error_Notice`。 **Example?2.15.?對會引發PHP 錯誤的代碼的返回值進行測試** ~~~ <?php class ErrorSuppressionTest extends PHPUnit_Framework_TestCase { public function testFileWriting() { $writer = new FileWriter; $this->assertFalse(@$writer->write('/is-not-writeable/file', 'stuff')); } } class FileWriter { public function write($file, $content) { $file = fopen($file, 'w'); if($file == false) { return false; } // ... } } ?> ~~~ ~~~ phpunit ErrorSuppressionTest PHPUnit 5.0.0 by Sebastian Bergmann and contributors. . Time: 1 seconds, Memory: 5.25Mb OK (1 test, 1 assertion) ~~~ 如果不使用錯誤抑制符,此測試將會失敗,并報告 ~~~ fopen(/is-not-writeable/file): failed to open stream: No such file or directory ~~~。
                  <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>

                              哎呀哎呀视频在线观看