background image

例如:

  

1.脚本所需的变量可以被定义为局部变量封装起来,如$connection 作为一个数据库连

接。

  

2.不是原本 PHP 的内置函数,应该加上对象来调用,如:header()写成$this->header()。

  具体代码

  这就是我们要测试的事务脚本对象,具体到脚本中,我们还需要封装:

 

  

  

class ForumPosting

  

{

  

private $headers = array();

  

public function handleRequest($postRequest)

  

{

  

$_POST = $postRequest;

  

$connection = $this->getAConnection();

  

ob_start();

  

include 'forum/post_new_copy.php';

  

$content = ob_get_clean();

  

return array(

  

'content' => $content,

  

'headers' => $this->headers

  

);

  

}