<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 單元測試(Unit testing) 適當的測試有幫于更好的編寫軟件。如果你設置了適當的測試用例,可以消除大多數功能性的錯誤,并且更好地維護你的軟件。 ## 整合 PHPunit 到 phalcon(Integrating PHPunit with phalcon) 如果你還沒有安裝好 phpunit,可以使用以下 composer 命令: ~~~ composer require phpunit/phpunit:^5.0 ~~~ 或者手動添加 composer.json: ~~~ { "require-dev": { "phpunit/phpunit": "^5.0" } } ~~~ phpunit 安裝后將會在你的根目錄創建一個名為 ‘tests’ 的目錄: ~~~ app/ public/ tests/ ~~~ 接下來,我們需要用一個 ‘helper’ 文件來引導單元測試程序。 ## PHPunit 輔助文件(The PHPunit helper file) 需要使用 helper 文件來引導運行測試程序。我們預先準備好一個示例文件,將該文件放到 tests/ 目錄下并命名為 TestHelper.php ~~~ <?php use Phalcon\Di; use Phalcon\Di\FactoryDefault; use Phalcon\Loader; ini_set("display_errors", 1); error_reporting(E_ALL); define("ROOT_PATH", __DIR__); set_include_path( ROOT_PATH . PATH_SEPARATOR . get_include_path() ); // Required for phalcon/incubator include __DIR__ . "/../vendor/autoload.php"; // Use the application autoloader to autoload the classes // Autoload the dependencies found in composer $loader = new Loader(); $loader->registerDirs( [ ROOT_PATH, ] ); $loader->register(); $di = new FactoryDefault(); Di::reset(); // Add any needed services to the DI here Di::setDefault($di); ~~~ 你需要從自己的 library 類庫中測試組件,將它們添加到 autoloader 加載器或在主程序中使用 autoloader 加載器。 為了更好地幫助你構建單元測試,我們寫了一些抽象的類庫,你可以使用這些抽象類來引導單元測試。 這些文件在 @[https://github.com/phalcon/incubator](https://github.com/phalcon/incubator). 你可以添加 incubator 依賴庫: ~~~ composer require phalcon/incubator ~~~ 或手動添加到 composer.json: ~~~ { "require": { "phalcon/incubator": "^3.0" } } ~~~ 你也可以使用鏈接克隆倉庫。 ## PHPunit.xml 文件(PHPunit.xml file) 現在,創建一個 phpunit 文件: ~~~ <?xml version="1.0" encoding="UTF-8"?> <phpunit bootstrap="./TestHelper.php" backupGlobals="false" backupStaticAttributes="false" verbose="true" colors="false" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" syntaxCheck="true"> <testsuite name="Phalcon - Testsuite"> <directory>./</directory> </testsuite> </phpunit> ~~~ 按照你的需求修改 phpunit.xml 然后保存到 tests/ 目錄。 你將在 tests/ 目錄運行所有測試。 ## 簡單的單元測試(Sample unit test) 要運行任何單元測試,你要事先定義好。autoloader 加載器將確保正確的文件被加載進來,所以你需要做的是創建文件然后 phpunit 運行測試。 該示例不包含配置文件,但大多數測試用例都需要配置文件,你可以將它添加到 DI 得到 UnitTestCase 文件。 首先在 /tests 目錄創建一個 UnitTestCase.php 基本單元測試: ~~~ <?php use Phalcon\Di; use Phalcon\Test\UnitTestCase as PhalconTestCase; abstract class UnitTestCase extends PhalconTestCase { /** * @var bool */ private $_loaded = false; public function setUp() { parent::setUp(); // Load any additional services that might be required during testing $di = Di::getDefault(); // Get any DI components here. If you have a config, be sure to pass it to the parent $this->setDi($di); $this->_loaded = true; } /** * Check if the test case is setup properly * * @throws \PHPUnit_Framework_IncompleteTestError; */ public function __destruct() { if (!$this->_loaded) { throw new \PHPUnit_Framework_IncompleteTestError( "Please run parent::setUp()." ); } } } ~~~ 獨立命名空間的單元測試是一個很好的主意,對于這個測試創建命名空間 ‘Test’,即創建一個文件名為 testsTestUnitTest.php: ~~~ <?php namespace Test; /** * Class UnitTest */ class UnitTest extends \UnitTestCase { public function testTestCase() { $this->assertEquals( "works", "works", "This is OK" ); $this->assertEquals( "works", "works1", "This will fail" ); } } ~~~ 你現在可以在命令行 tests 目錄執行 ‘phpunit’ 得到以下輸出: ~~~ $ phpunit PHPUnit 3.7.23 by Sebastian Bergmann. Configuration read from /private/var/www/tests/phpunit.xml Time: 3 ms, Memory: 3.25Mb There was 1 failure: 1) Test\UnitTest::testTestCase This will fail Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'works' +'works1' /private/var/www/tests/Test/UnitTest.php:25 FAILURES! Tests: 1, Assertions: 2, Failures: 1. ~~~ 現在,你可以開始構建單元測試了。你可以在這里查看一份很好的指南(如果你不熟悉PHPUnit,我們也推薦閱讀PHPUnit文檔) [http://blog.stevensanderson.com/2009/08/24/writing-great-unit-tests-best-and-worst-practises/](http://blog.stevensanderson.com/2009/08/24/writing-great-unit-tests-best-and-worst-practises/)
                  <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>

                              哎呀哎呀视频在线观看