1. 程式人生 > >yaf框架編寫測試用例

yaf框架編寫測試用例

div testin auto 單元測試 invoke ica oot name phpunit

https://phpunit.de/manual/current/zh_cn/phpunit-book.html phpunit單元測試中文文檔 目錄結構: test ├── controllers │ ├── BaseControllerTest.php │ └── IndexControllerTest.php ├── modules │ └── Testdemo │ │ ├── controllers │ │ │ ├── ApiTest.php ├── index.php ├── phpunit.xml └── composer.json 在tests目錄下放置composer.json文件: { "require-dev": { "phpunit/phpunit": "^6.1", "phpunit/php-invoker": "^1.1", "phpunit/dbunit": "^3.0" } } 安裝composer:composer install 入口文件配置:tests/index.php <?php date_default_timezone_set("Asia/Shanghai"); define(‘ENVIRONMENT‘, ‘develop‘); include ‘./vendor/autoload.php‘; define(‘APPLICATION_PATH‘, dirname(dirname(__FILE__))); define("VIEWS_PATH", APPLICATION_PATH."/application/views"); $application = new Yaf_Application( APPLICATION_PATH . "/conf/application.ini"); $application->bootstrap()->run(); ?> 在tests/phpunit.xml文件中引入入口文件: <phpunit bootstrap="./index.php"> <testsuites> <!--<testsuite name="controllers">--> <!--<file>./controllers/DemoTest.php</file>--> <!--</testsuite>--> <!--<testsuite name="models">--> <!--<file>./models/UserTest.php</file>--> <!--</testsuite>--> <!--<testsuite name="models/Mysql">--> <!--<file>./models/Mysql/UserTest.php</file>--> <!--</testsuite>--> <!--<testsuite name="models/Redis">--> <!--<file>./models/Redis/UserTest.php</file>--> <!--</testsuite>--> <!--<testsuite name="modules/Testdemo">--> <!--<file>./modules/Testdemo/controllers/ApiTest.php</file>--> <!--</testsuite>--> </testsuites> </phpunit> 在tests目錄下運行ApiTest測試文件命令行: phpunit --stderr ./modules/Testdemo/controllers/ApiTest.php 註:--stderr 是指直接輸出,不會經過緩存,屏蔽header帶出來的錯誤 phpunit --stderr --filter ‘testIndex‘ ./modules/Testdemo/controllers/ApiTest.php 註:‘testIndex‘是指只運行ApiTest.php裏邊的Index測試塊,即testIndex方法

yaf框架編寫測試用例