ninny project 单元测试框架使用说明

系统运行要求 PHPUnit 3.1.x PHPUnit 的安装 参考:http://www.phpunit.de/pocket_guide/3.1/en/installation.html 建议使用 Pear 方式安装。 Pear 包的安装请参考http://pear.php.net/manual/en/installation.php 测试用例的编写 参考:http://www.phpunit.de/pocket_guide/3.1/en/writing-tests-for-phpunit.html 应注意,在本框架使用中实际无需在测试用例加载任何文件。 配置文件的设置 <?xml version=’1.0′ encoding=’UTF-8′ ?> <AllTests> <TestSuite> <name>FoobarTest</name> <require>AnotherFoobar.php</require> </TestSuite> <Test> <class>Foo_Bar_AllTest</class> <method>suite</method> <require>/home/foo/bar/AnotherLib.php</require> </Test> </AllTests> TestSuite? 标签指定需要加载的单元测试用例。name 标签指定测试用例名(类名)。 Test 为一组单元测试用例。class 标签指定测试用例组类名,method 标签指定该类返回 PHPUnit_Framework_TestSuite 实例的类方法。 类名的命名应遵从 Zend Framework 的命名规则,即下划线分隔文件路径作为类名。如:类文件存放于 Foo/Bar/AllTest.php,则类对应为 class Foo_Bar_AllTest {…}。 测试用例和测试用例组都将自动加载。保存于 include path 下,符合 Zend Framework 类命名规范的类也都将自动加载(使用 Zend_Loader::registerAutoload() …

在 Zend Framework 中使用 Jquery 的 ajax 功能

发现不少人对此有迷惑,所以有通常的做法:设置 noViewRender,然后将 ajax 调用时的返回数据直接输出于 controller 中。 个人以为,这种做法不是不可以。但是在 Zend Framework 中这样使用,就有违 MVC 的分离原则。controller 不应该区分显示到客户端的是页面还是 json 或者 xml。 下面是我的做法,仅供参考。部分调用了 ninny project 中封装的功能凑合看吧: ———————–view script: index.php————————— <?php echo $this->jquery();?> <script language="javascript"> // jquery ajax 的 json $().ready( function(){ $("#load").click( function() { $.getJSON("/foobar/index/ajax",function(data){ $("#title").html(data.title); content = ""; $.each(data.content, function(i, line){ content += line + "<br/>"; }); $("#content").html(content); }); }); …