单测中有个普遍性的问题,被侧类中的private方法无法直接调用。小拽在处理过程中通过反射改变方法权限,进行单测,分享一下,直接上代码。
简单被测试类
生成一个简单的被测试类,只有个private方法。
单测代码
<?php /*************************************************************************** * * $Id: MyClassTest T,v 1.0 PsCaseTest cuihuan Exp$ * **************************************************************************//** * 崔小涣单测的基本模板。 * * @author cuihuan * @date 2015/11/12 22:09:31 * @version $Revision:1.0$ **/require_once ('./MyClass.php');class MyClassTest extends PHPUnit_Framework_TestCase {const CLASS_NAME = 'MyClass';const FAIL = 'fail';protected $objMyClass;/** * @brief setup: Sets up the fixture, for example, opens a network connection. * * 可以看做phpunit的构造函数 */public function setup() {date_default_timezone_set('PRC');$this->objMyClass = new MyClass();}/** * 利用反射,对类中的private 和 protect 方法进行单元测试 * * @