`

yii 单元测试

阅读更多
第一步:BaseTestCase.php
<?php

define("REAL_PATH", "E:/wwwroot/eetopin/");
require_once ('PHPUnit/Framework/TestCase.php');
require (REAL_PATH.'eetopinWebConfig/config.php');

define ( 'EETOPIN_WEB_LIB', REAL_PATH.'eetopinWebLib/' );
define ( 'EETOPIN_PUBLIC', REAL_PATH.'eetopinPublic/' );
define ( 'ROOT_PATH', dirname ( __FILE__ ) . DIRECTORY_SEPARATOR );
define ( 'SYSTEM_NAME', 'eetopin' );
define ( 'EETOP_PATH', ROOT_PATH . SYSTEM_NAME );
define ( 'COMMON_LIB_PATH', EETOPIN_WEB_LIB . 'common_lib' );
define ( 'EETOPIN_PUBLIC_PATH', EETOPIN_PUBLIC . 'in_public' );
define ( 'SITE_NAME', '' );
define ( 'EETOP_DEFAULT_THEME', 'blue'); // 默认主题

//设置别名
Yii::setPathOfAlias ( SYSTEM_NAME, EETOP_PATH );
Yii::setPathOfAlias ( 'common_lib', COMMON_LIB_PATH );
Yii::setPathOfAlias ( 'in_public', EETOPIN_PUBLIC_PATH );
$config =  REAL_PATH.'eetopinWeb/eetopin/config/main.php';
$config = require($config);

foreach ($config['import'] as $one) {
	Yii::import($one);
}
		
class BaseTestCase extends PHPUnit_Framework_TestCase {

}

?>



第二步:具体的业务类测试
DeptServiceTest.php
<?php

require ('./base/BaseTestCase.php');
		
class DeptServiceTest extends BaseTestCase {
	
	private $deptService;
	
	public function setUp() {
		$this->deptService = new DeptService();		
	}
	
	public function testQuery() {
		$list = $this->deptService->listDept(127);
		var_dump($list);
		$key = 0;
		$this->assertArrayHasKey($key, $list);
	}
	
	public function tearDown() {
		var_dump('---------end----------');
	}

}

?>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics