1.入门
https://netbeans.org/kb/trails/php_zh_CN.html
NetBeans是开源软件开发集成环境,是一个开放框架,可扩展的开发平台,可以用于Java、C/C++,PHP等语言的开发,本身是一个开发平台,可以通过扩展插件来扩展功能。
2.搭环境
软件,插件等参照 文件中的NetBeans.rar
前提:wamp server环境OK
准备谷歌自由版(netbeans插件ok)
a.首先必须先安装jdk-8u40-nb-8_0_2-windows-x64.exe
b.安装netbeans-8.0.2-windows.exe
c.将以下3个插件放在wamp\bin\php\php5.5.12 目录中
更新wamp\bin\php\php5.5.12\zend_ext\php_xdebug的dll文件版本
d.设置电脑环境变量
e.安装pear(规范你的代码,并便于日后快速生成文档)
在管理员权限下运行,运行后,会生成对应文件及文件夹
D:\wamp\bin\php\php5.5.12\php.ini
中自动插入path路径
f.追加pear环境变量
g.修改2个文件夹中的php.ini文件
1)wamp\bin\php\php5.5.12\php.ini
可以变动下pear文件的存放位置
修改php_xdebug文件名字
添加以下内容
xdebug.remote_enable=on xdebug.remote_handler=dbgp xdebug.remote_host=127.0.0.1 xdebug.remote_port=9000 xdebug.auto_trace=1 xdebug.collect_params=1 xdebug.collect_return=1 xdebug.trace_output_dir="d:/wamp/xdebug/trace" xdebug.profiler_enable=1 xdebug.profiler_output_name = cachegrind.out.%t.%p xdebug.profiler_output_dir="d:/wamp/xdebug/profiler"
2)wamp\bin\apache\apache2.4.9\bin\php.ini
同样
3.启动wampserver的服务
打开netbeans软件
文件-新建项目
下一步
下一步
完成
工具-选项-常规
web浏览器-编辑
添加新的浏览器,使用文件夹中的谷歌自由版,里面有netbeans相关插件
选项-PHP-常规
添加解析器
框架和工具
选择phpunit,添加phpunit脚本和框架生成器脚本
4.创建完项目后,修改属性-测试,phpunit打勾
5.选中某个源文件中的需要测试的php文件,单击右键“工具”-“创建测试”,输入测试文件存放目录
生成xxxtest.php文件,修改代码,执行测试任务
6.举例
源文件test.php
----------------------------------------
<?php /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * Description of Sample * * @author sicnco */ class Sample { //put your code here public function Get($a) { if($a==1) { return 'ok:'.$a; } else { return 'ng:'.$a; } } }
--------------------------------------
修改后的测试文件testtest.php
<?php require_once '../test.php'; <------这一行需要手动添加 /** * Generated by PHPUnit_SkeletonGenerator on 2015-03-27 at 03:50:41. */ class SampleTest extends PHPUnit_Framework_TestCase { /** * @var Sample */ protected $object; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { $this->object = new Sample; } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown() { } /** * @covers Sample::Get * @todo Implement testGet(). */ public function testGet() { $rlt = $this->object->Get(1); <----需要写代码,验证 $this->assertEquals($rlt, 'ok:1'); <----验证代码运行结果 } }
点击测试文件testtest.php右键,选中“运行”,查看测试结果