Php $this->;调度(';/';)指zend测试中的调度
我正在为zend项目编写单元测试, 我想知道Php $this->;调度(';/';)指zend测试中的调度,php,unit-testing,oop,Php,Unit Testing,Oop,我正在为zend项目编写单元测试, 我想知道 <?php class IndexControllerTest extends ControllerTestCase { public function testHomePage() { $this->dispatch('/'); } } 在面向对象编程中,当一个类扩展另一个类时,它继承其父类(它正在扩展的类)的方法(或函数) 您可以使用$this->
<?php
class IndexControllerTest extends ControllerTestCase
{
public function testHomePage() {
$this->dispatch('/');
}
}
在面向对象编程中,当一个类扩展另一个类时,它继承其父类(它正在扩展的类)的方法(或函数)
您可以使用$this->method
从类本身或其子类(扩展它的其他类)中调用类方法
鉴于IndexControllerTest
中未定义dispatch
,因此它必须是ControllerTestCase
的函数(它扩展了IndexControllerTest
并将字符串'/'
传递给它
查看类ControllerTestCase
,将有一个名为dispatch
的函数,您可以看到它在那里做什么。从对该方法的注释:
* 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.
@Flavius我已经说过我是zend framework和phpunit的新手,我只需要一些帮助而不仅仅是批评!不要太严厉地接受批评,这是旅程的一部分。只要不断地问问题,你就会找到你要去的地方。@温和的绒毛谢谢你,我知道了!我想他问的不是如何调用dispatch()(以及该方法在何处声明),而是“/”参数的含义。我真的想知道“/”参数的含义。如果你按照我的答案去做,你会发现的。你可以通过使用一些IDE(例如NetBeans或PhpStorm)很容易找到它。IDE不应该取代能力。首先要学会手工操作,然后当你已经是一名称职的程序员,而你的老板要求你提高工作效率时,就跳转到IDE上去。这首先是一个IDE。其余的都是(想要的)使用它的副作用。+1是为了自己找到它,这基本上就是我建议的。:)@Flavius,能力和从IDE中学习并不是相互排斥的。建议人们在“毕业”之前学会在记事本上编程以获得使用IDE的特权是愚蠢的。
* 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.