Zend Studio 本身是支持phpunit 测试,而我们的需求是测试用例代码中无需直接加载
而其提供的工具无法满足此要求。最终只能通过修改Zend Studio插件的方式才能来满足要求
1、修改Zend Studio 插件phpunit 代码
打开文件:
D:\Program Files\Zend\Zend Studio 9.0.4\plugins
\com.zend.php.phpunit_9.0.4.201210081806\resources\ZendPHPUnit.php
找到
require_once 'PHPUnit/Autoload.php';
require_once'PHPUnit/Framework/Error/Notice.php';
require_once'PHPUnit/TextUI/TestRunner.php'
在require_once'PHPUnit/TextUI/TestRunner.php' 下加入代码
$_tcfile = $GLOBALS['ZendPHPUnitTests'][0];
if ($_tcfile['file']) {
//找出项目名称,或测试类型
preg_match('/(.+)\/test\/([A-Za-z]+)\/([A-Za-z]+)\//',str_replace('\\','/',$_tcfile['file']), $_phpunittmatch);
require_once $_phpunittmatch[1].'/test/'.$_phpunittmatch[2].'/'.$_phpunittmatch[3].'Init.php';
}
运行测试文件:UserServiceTest.php,把文件中下面的代码删除
require_once'PHPUnit/Autoload.php';
require_once'../ServiceInit.php';
在UserServiceTest.php上右键->run as ->phpunittest,这时会显示phpunit 插件框,会显示红条,绿条表示测试通过与否,截图看看
特别说明:
在UserServiceTest.php上右键 这步必须!!!!!!!!
2、Zend Studio 配置外部工具执行phpunit
点击run->external tools->external tools Configurations, 如图
点击小下拉箭头取消Filter Configuration Type
双击Program 自动创建外部工具
#命令的地址
location:D:\Program Files\wamp\bin\php\php5.3.3\phpunit.bat
#执行命令的目录
working:${project_loc}
#执行命令的参数
arguments:--bootstrap=test/Web/Library/ServiceInit.php${resource_loc}
如图
点击Common,在dispaly in favorites menu 选择显示的菜单,打钩就行
执行外部工具
点击run->external tools->外部工具名称,前面是绿色图标的名称 点击它