1,安裝pear 用官方的方法 :request http://pear.php.net/go-pear.phar in your browser and save the output to a local file go-pear.phar. You can then run 「 php go-pear.phar」in a Windows Command Prompt to start the update process. After changing php.ini , you need to restart your web server. (http://pear.php.net/manual/en/installation.getting.php)php
2 ,安裝phpunithtml
先安裝下列包 pear channel-discover pear.phpunit.de pear channel-discover components.ez.no pear channel-discover pear.symfony-project.com pear update-channels pear upgrade-all 最後運行 pear install phpunit/PHPUnit或者pear install --alldeps phpunit/PHPUnitweb
3,安裝過程種出現這個錯誤時:No releases available for package "pear.phpunit.de/PHPUnit 用 pear clear-cache清一下緩存就行了。api
4,安裝後執行結果:緩存
test1.php的內容:測試
<!-- lang: php --> <?php require '../wx.php'; class wxTest extends PHPUnit_Framework_TestCase{ public $o = null; //初始化時 function setUp(){ $this->o = new wechatCallbackapiTest(); } //測試後清除此類 function tearDown(){ unset($this->o); } function testStr(){ foreach(array('adsfasdjl...k','jianli','個人簡歷','sdfs簡歷dfa') as $value){ $this->assertTrue($this->o->checkResume($value)); } } }
wechatCallbackapiTest 此類的checkResume()方法代碼:ui
<!-- lang: php --> function checkResume($content){ $resum_keywords = array('jl','jianli','簡歷'); foreach ($resum_keywords as $key => $value) { if(preg_match("/$value/i", $content)) return true; } return false; }
別人的相關博文: http://flyer0126.iteye.com/blog/1441817 http://hi.baidu.com/wuhui/item/17986ed5d9a90893260ae729 http://www.cnblogs.com/zhja/archive/2013/02/28/2937046.html http://blog.csdn.net/jucrazy/article/details/6720935this
phpunit 手冊 :http://phpunit.de/manual/3.7/en/index.html.net