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

   application  
      modules  
         users  
           controllers  
            .  
            .  
        lessons  
        reports  
        blog  

我对“博客”中的控制器进行了单位测试,该测试的内容类似于代码的以下部分:我肯定做了一些非常错误或缺少某些事情 - 就像我运行测试时,我没有错误,没有成功消息(这通常像...好的(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();
   }
}
有帮助吗?

解决方案

public/index.php 文件是用于引导您的应用程序进行Web查看的脚本。我认为您不应该将其包含在测试脚本中。另外,您可以通过引用避免所有这些相对路径 APPLICATION_PATH.

require_once '../../../../public/index.php';
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top