Pergunta

I'm using the zend modular director structure, i.e.

   application  
      modules  
         users  
           controllers  
            .  
            .  
        lessons  
        reports  
        blog  

I have a unit test for a controller in 'blog' that goes something like the below section of code: I'm definitely doing something very wrong, or missing something - as when i run the test, i get no error, no success message (that goes usually like ...OK (2 tests, 2 assertions)). I get all the text from layout.phtml, where i have the global site layout.

This is my first endeavor writing a unittest for zend-M-V-C structure so probably I'm missing something important?

Here goes....

 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();
   }
}
Foi útil?

Solução

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';
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top