Zend Framework 1.5 快要出来了

看到邮件列表上说,于 1 月 22 日冻结代码,计划 1 月 24 日正式发布。
增加了不少新的功能,正式发布的时候还可能有更多的一些功能:
  * Zend_Auth_Adapter_Ldap
  * Zend_Build/Zend_Console
  * Zend_Controller additional action helpers
    * ContextSwitch and AjaxContext
    * Json
    * AutoComplete
  * Zend_Form
  * Zend_InfoCard
  * Zend_Layout
  * Zend_OpenId
  * Zend_Search_Lucene improvements:
    * wildcard search
    * date range search
    * fuzzy search
    * Lucene 2.1 index file format support
  * Zend_View enhancements:
    * actions
    * partials
    * placeholders
  * Zend_Pdf UTF8 support
  * New Zend_Service consumables (final list TBD)
  * A whole lotta bug fixes and documentation improvements

 

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() 方法)。若还需加载其他文件,应指定 require 标签,require 标签内容为待加载文件的完整路径或相对于测试目录(tests)的相对路径。

 

执行测试

  1. php 的 cli 程序应在系统 PATH 中。
  2. PHPUnit 的执行程序应在系统 PATH 中(Windows 下为 PHPUnit.bat,Linux 下为 PHPUnit.sh)。

All Tests

进入测试框架所在目录,执行 php AllTests?.php。

One Test

进入测试框架所在目录,执行 php OneTest?.php Test_Name。

改进方向

  • 迭代测试用例,子集测试用例可作为独立的测试执行,亦可通过配置文件加载入上级测试执行。
  • 通过配置文件自动生成测试用例框架,编写测试时只需要填写相应测试断言。

在 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);
});
});
});
</script>
<div id="title"></div><div id="content"></div><input type="button" id="load" value="Load"/>
-----------------------view script: ajax.php---------------------------
<?php
// Zend_Json 处理输出的对象,如果这里不使用 Zend_Json,可使用其他编码器将 php 对象进行编码输出。
// 这样在需要修改输出类型时,仅需要修改视图部分。而不涉及数据模型或控制器。
echo Zend_Json::encode($this->content);
?>

———————–action controller: Foobar_IndexController.php—————————

<?php
class Foobar_IndexController extends Ifang_Controller_Action
{
public function indexAction()
{
}
public function ajaxAction()
{
$foobar = array(
'title' => 'This is a test!',
'content' => array(
'0' => 'This is the first line!',
'1' => 'This is the second line!',
'2' => 'This is the last line!',
),
);
// 传递一个普通的 php 对象(变量)到视图。
$this->view->content = $foobar;
}
}

An issue about Zend_Translate_Adapter

My codes is:

public function testGetTextTw()

{

    $t = new Zend_Translate(‘gettext’, ‘./_locale/’, ‘zh_TW’);

    $this->assertEquals(‘n2’, $t->_(‘New’));

}

public function testGetTextCn()

{

    $t = new Zend_Translate(‘gettext’, ‘./_locale/’, ‘zh_CN’);

    $this->assertEquals(‘n1’, $t->_(‘New’));

}

But, the testGetTextCn() go into fail: expected string ‘n1’ but got string ‘n2’.

So, I read the codes in Zend_Translate_Adapter::__construct().
the param variable $local was covered by an other value.

I made this patch:

zend_translate_adapter patch

Now, it works fine!

The issue and the patch have been submited to issue tracker:

framework.zend.com/issues/browse/ZF-2205

 

【翻译】确保项目失败的十种途径

曾经在网上见过一个翻译的非常糟糕的摘要,完全扭曲了原文的意思。随即开始自己翻译。看能不能翻译出原文的韵味来。

原文:http://vbnotebookfor.net/2007/08/19/10-ways-to-insure-project-failure/

If you want your next software development project to fail, and not just a small way but in big, spectacular, way, here are some sure fire steps for you to follow:

如果你希望你的下一个开发项目失败,并且不是一个小小的失败,而是彻头彻尾的失败,这里有一些必须遵从的步骤。 Continue reading “【翻译】确保项目失败的十种途径”

安全升级 Blog 到 wordpress 2.3

按照向导安全升级,暂时没发现有问题。先用用看吧。

wordpress 2.3 自带了 tags 功能,只要在”Manage“中的”Import“功能里选择”Import Ultimate Tag Warrior“,然后就可以将所有 tags 导入。超级方便,哈哈~

使用其他 tags 插件也提供了相应的导入,不知道是不是一样方便。

不过遗憾的是,由于原分类表被删除,Google Sitemap 的插件不能用了。