0

我正在使用zend模块化导演结构,即

   application  
      modules  
         users  
           controllers  
            .  
            .  
        lessons  
        reports  
        blog  

我在“博客”中有一个控制器的单元测试,类似于下面的代码部分:我肯定做错了什么,或者遗漏了一些东西 - 当我运行测试时,我没有收到错误,没有成功消息(这通常像 ...OK(2 个测试,2 个断言))。我从 layout.phtml 中获取所有文本,其中我有全局站点布局。

这是我第一次尝试为 zend-MVC 结构编写单元测试,所以我可能遗漏了一些重要的东西?

开始....

 require_once '../../../../public/index.php';
 require_once '../../../../application/Bootstrap.php';
 require_once '../../../../application/modules/blog/controllers/BrowseController.php';
 require_once '../../../TestConfiguration.php';

 class Blog_BrowseControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
 { 
    public function setUp() {
        $this->bootstrap = array($this, 'appBootstrap');
        Blog_BrowseController::setUp();
    }

   public function appBootstrap() {
      require_once dirname(__FILE__) . '/../../bootstrap.php';

   }

    public function testAction() {
      $this->dispatch('/');
      $this->assertController('browse');
      $this->assertAction('index');
   }

   public function tearDown() {
     $this->resetRequest();
     $this->resetResponse();
     Blog_BrowseController::tearDown();
   }
}
4

1 回答 1

1

The public/index.php file is the script used to bootstrap your application for web viewing. I don't think you should be including it in your test script. Also, you can avoid all of those relative paths by referencing APPLICATION_PATH.

require_once '../../../../public/index.php';
于 2010-04-21T19:34:18.213 回答