【发布时间】:2012-01-03 15:42:34
【问题描述】:
关于 CakePHP 中的单元测试,它似乎是两种主要测试动作的方式。
第一个是使用generate() 方法模拟涉及的控制器:
$Posts = $this->generate('Posts', array(
'methods' => array(
'isAuthorized'
),
'models' => array(
'Post' => array('save')
),
'components' => array(
'RequestHandler' => array('isPut'),
'Email' => array('send'),
'Session'
)
));
但是in CakePHP 2 a new ControllerTestCase class has been added 显然简化了这个配置:
class PostControllerTest extends ControllerTestCase {
public $fixtures = array('app.post');
function testIndex() {
$result = $this->testAction('/post/index');
debug($result);
}
...
}
我在通过 ControllerTestCase 类使用组件时发现了几个问题。我想知道这两种方法之间有什么区别(如果有的话)。
谢谢!
【问题讨论】:
标签: php unit-testing cakephp controller components