views:

34

answers:

1

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();
   }
}
+1  A: 

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';
awgy
Off topic. Hey awgy, why did you delete your answer about `gcc`? That was correct I was about to mark you as accepted.
OscarRyz
Sorry about that-- another user had posted about `/usr/bin/gcc` and using `pkgutil`, and I thought my answer was inaccurate. It would appear that I have `gcc` in two locations, which doesn't make sense to me. I would normally let the votes decide, but I thought I had made some mistake or oversight and didn't want to mislead anyone.Glad that my answer helped you, though! Now to find out why there are two copies of `gcc`...
awgy
Hi, Thanks,As it turns out, the error was due to the configuration in the bootstrap file - i was declaring the class twice, and the error was not showing up on screen (? why?) but found it in the php error logs.Thanks for taking the time to answer though!
Mallika Iyer