What does $this->dispatch('/') means in zend test
I am writing unit test for zend project, I want to know
<?php
class IndexControllerTest extends ControllerTestCase
{
public function testHomePage() {
$this->dispatch('/');
}
}
The ControllerTestcase.php extends Zend/Test/PHPUnit/ControllerTestCase.php
<?php
require_once 'Zend/Application.php';
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
class ControllerTestCase
extends Zend_Test_PHPUnit_ControllerTestCase
{
protected $application;
public function setUp() {
$this->bootstrap = array($this,'appBootstrap');
parent::setUp();
}
public function appBootstrap() {
$this->application =
开发者_高级运维new Zend_Application(APPLICATION_ENV,
APPLICATION_PATH.'/configs/application.ini');
$this->application->bootstrap();
}
}
what does $this->dispatch('/'); means? does this mean forward to request to root of the application?
From comment to this method:
* Dispatch the MVC
*
* If a URL is provided, sets it as the request URI in the request object.
* Then sets test case request and response objects in front controller,
* disables throwing exceptions, and disables returning the response.
* Finally, dispatches the front controller.
http://framework.zend.com/svn/framework/standard/tags/release-1.9.8/library/Zend/Test/PHPUnit/ControllerTestCase.php
In object oriented programming, when a class extends another, it inherits the methods (or functions) of its parent class (the class it is extending).
You can use $this->method
to call a classes methods from within itself or its descendents (other classes that extend it).
given that dispatch
is not defined in IndexControllerTest
, it must be a function of ControllerTestCase
(which IndexControllerTest
extends) and it is passing the string '/'
to it.
Have a look for the class ControllerTestCase
and there will be a function called dispatch
, you can see what that is doing there.
精彩评论