<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、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 對異常進行測試 [Example?2.10, “使用 @expectedException 標注”](# "Example?2.10.?使用 @expectedException 標注")展示了如何用 `@expectedException` 標注來測試被測代碼中是否拋出了異常。 **Example?2.10.?使用 @expectedException 標注** ~~~ <?php class ExceptionTest extends PHPUnit_Framework_TestCase { /** * @expectedException InvalidArgumentException */ public function testException() { } } ?> ~~~ ~~~ phpunit ExceptionTest PHPUnit 5.0.0 by Sebastian Bergmann and contributors. F Time: 0 seconds, Memory: 4.75Mb There was 1 failure: 1) ExceptionTest::testException Expected exception InvalidArgumentException FAILURES! Tests: 1, Assertions: 1, Failures: 1. ~~~ 另外,你可以將 `@expectedExceptionMessage`、`@expectedExceptionMessageRegExp` 和 `@expectedExceptionCode` 與 `@expectedException` 聯合使用,來對異常的訊息與代號進行測試,如[Example?2.11, “使用 `@expectedExceptionMessage`、`@expectedExceptionMessageRegExp` 和 `@expectedExceptionCode` 標注”](# "Example?2.11.?使用 @expectedExceptionMessage、@expectedExceptionMessageRegExp 和 @expectedExceptionCode 標注")所示。 **Example?2.11.?使用 `@expectedExceptionMessage`、`@expectedExceptionMessageRegExp` 和 `@expectedExceptionCode` 標注** ~~~ <?php class ExceptionTest extends PHPUnit_Framework_TestCase { /** * @expectedException InvalidArgumentException * @expectedExceptionMessage Right Message */ public function testExceptionHasRightMessage() { throw new InvalidArgumentException('Some Message', 10); } /** * @expectedException InvalidArgumentException * @expectedExceptionMessageRegExp #Right.*# */ public function testExceptionMessageMatchesRegExp() { throw new InvalidArgumentException('Some Message', 10); } /** * @expectedException InvalidArgumentException * @expectedExceptionCode 20 */ public function testExceptionHasRightCode() { throw new InvalidArgumentException('Some Message', 10); } } ?> ~~~ ~~~ phpunit ExceptionTest PHPUnit 5.0.0 by Sebastian Bergmann and contributors. FFF Time: 0 seconds, Memory: 3.00Mb There were 3 failures: 1) ExceptionTest::testExceptionHasRightMessage Failed asserting that exception message 'Some Message' contains 'Right Message'. 2) ExceptionTest::testExceptionMessageMatchesRegExp Failed asserting that exception message 'Some Message' matches '#Right.*#'. 3) ExceptionTest::testExceptionHasRightCode Failed asserting that expected exception code 20 is equal to 10. FAILURES! Tests: 3, Assertions: 6, Failures: 3. ~~~ 關于 `@expectedExceptionMessage`、`@expectedExceptionMessageRegExp` 和 `@expectedExceptionCode`,分別在[the section called “@expectedExceptionMessage”](# "@expectedExceptionMessage")、[the section called “@expectedExceptionMessageRegExp”](# "@expectedExceptionMessageRegExp") 和 [the section called “@expectedExceptionCode”](# "@expectedExceptionCode")有更多相關范例。 此外,還可以用 `setExpectedException()` 或 `setExpectedExceptionRegExp()` 方法來設定所預期的異常,如[Example?2.12, “預期被測代碼將引發異常”](# "Example?2.12.?預期被測代碼將引發異常")所示。 **Example?2.12.?預期被測代碼將引發異常** ~~~ <?php class ExceptionTest extends PHPUnit_Framework_TestCase { public function testException() { $this->setExpectedException('InvalidArgumentException'); } public function testExceptionHasRightMessage() { $this->setExpectedException( 'InvalidArgumentException', 'Right Message' ); throw new InvalidArgumentException('Some Message', 10); } public function testExceptionMessageMatchesRegExp() { $this->setExpectedExceptionRegExp( 'InvalidArgumentException', '/Right.*/', 10 ); throw new InvalidArgumentException('The Wrong Message', 10); } public function testExceptionHasRightCode() { $this->setExpectedException( 'InvalidArgumentException', 'Right Message', 20 ); throw new InvalidArgumentException('The Right Message', 10); } } ?> ~~~ ~~~ phpunit ExceptionTest PHPUnit 5.0.0 by Sebastian Bergmann and contributors. FFFF Time: 0 seconds, Memory: 3.00Mb There were 4 failures: 1) ExceptionTest::testException Expected exception InvalidArgumentException 2) ExceptionTest::testExceptionHasRightMessage Failed asserting that exception message 'Some Message' contains 'Right Message'. 3) ExceptionTest::testExceptionMessageMatchesRegExp Failed asserting that exception message 'The Wrong Message' contains '/Right.*/'. 4) ExceptionTest::testExceptionHasRightCode Failed asserting that expected exception code 20 is equal to 10. FAILURES! Tests: 4, Assertions: 8, Failures: 4. ~~~ [Table?2.1, “用于對異常進行測試的方法 ”](# "Table?2.1.?用于對異常進行測試的方法")中列舉了用于對異常進行測試的各種方法。 **Table?2.1.?用于對異常進行測試的方法 ** | 方法 | 含義 | |-----|-----| | void setExpectedException(string $exceptionName[, string $exceptionMessage = '', integer $exceptionCode = NULL]) | 設定預期的 `$exceptionName`、`$exceptionMessage` 和 `$exceptionCode`。 | | void setExpectedExceptionRegExp(string $exceptionName[, string $exceptionMessageRegExp = '', integer $exceptionCode = NULL]) | 設定預期的 `$exceptionName`、`$exceptionMessageRegExp` 和 `$exceptionCode`。 | | String getExpectedException() | 返回預期異常的名稱。 | 可以用 [Example?2.13, “另一種對異常進行測試的方法”](# "Example?2.13.?另一種對異常進行測試的方法") 中所示方法來對異常進行測試。 **Example?2.13.?另一種對異常進行測試的方法** ~~~ <?php class ExceptionTest extends PHPUnit_Framework_TestCase { public function testException() { try { // ... 預期會引發異常的代碼 ... } catch (InvalidArgumentException $expected) { return; } $this->fail('預期的異常未出現。'); } } ?> ~~~ 當[Example?2.13, “另一種對異常進行測試的方法”](# "Example?2.13.?另一種對異常進行測試的方法") 中預期會引發異常的代碼并沒有引發異常時,后面對 `fail()` 的調用將會中止測試,并通告測試有問題。如果預期的異常出現了,將執行 `catch` 代碼塊,測試將會成功結束。
                  <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>

                              哎呀哎呀视频在线观看