【发布时间】:2014-04-10 22:32:29
【问题描述】:
我正在尝试学习如何在 CakePhp 中使用单元测试,我正在尝试编写控制器测试。我阅读了有关 testAction() 和 debug() 函数的信息,但它对我不起作用,我的意思是,测试方法通过了,但 debug() 返回 null(因为 testAction 确实如此)
这是我的代码:
<?php
App::uses('Controller', 'Controller');
App::uses('View', 'View');
App::uses('PostsController', 'Controller');
class PostsControllerTest extends ControllerTestCase {
public function setUp() {
parent::setUp();
$Controller = new Controller();
$View = new View($Controller);
$this->Posts = new PostsController($View);
}
public function testIndex() {
$result = $this->testAction('Posts/Index');
debug($result);
}
}
帖子/索引控制器返回存储在数据库中的所有帖子的列表。
【问题讨论】:
-
试试
$this->testAction('posts/index');