0
votes
class ControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{
    public $object;

    public function  setUp() {
        $this->bootstrap = array($this, 'boostrap');
        parent::setUp();
    }

    public function bootstrap(){
        $this->application = new Zend_Application(
                    APPLICATION_ENV,
                    APPLICATION_PATH . '/configs/application.ini'
                );
        $this->application->bootstrap();

    }

    public function testIndexAction(){
        // body
    }

}

This is the class for the test. My question is how to implement the testIndexAction where the actual command on the command prompt is:

php zfrun.php -a ..index

2
Where does zfrun.php come from? Can you link to its source or post it if it's short? Zend's ControllerTestCase is designed to be given a route for dispatching, rendering the view, and making assertions about the resulting content.David Harkness
zfrun.php comes from tests where it is also the root of the application. zfrun.php is like a bootstrap file. The actual bootstrap which is for the application Bootstrap.php also instantiates Zend_Console_Getopt which also defines the parameter to run the application.Efox

2 Answers

0
votes

Without seeing exactly what zfrun.php does, I can only guess, and it sounds like you need to ditch ControllerTestCase. ControllerTestCase is designed to mimic an HTTP request to send through the Zend dispatcher, but you don't need that.

Instead, you can try to mimic calling zfrun.php from the command line by setting up $argv as it would look and executing zfrun.php yourself:

function testIndexAction() {
    $argv = array(
            '-a',
            'module_name.controller_name.index',
        );
    require 'zfrun.php';
}

The problem is that this works for only one test, assuming zfrun.php defines classes or functions and cannot be required multiple times. Therefore, you'll need to do whatever zfrun.php does in a new test case base class without using zfrun.php itself. Essentially refactor its code into a reusable test helper method.

function executeControllerAction($module, $controller, $action) {
    ... whatever magic zfrun.php does ...
}
0
votes

If this is the test for your home page, use

$this->dispatch('/');

If not, you'll have to give it the URL that will trigger the route to load this controller.