2012-03-30 47 views
2

我只是试着用PHPPHP和CakePHP,并试图在控制器测试用例中使用testAction()方法时出现以下错误。CakePHP 2.1.1。 testAction()undefined

致命错误:调用未定义方法GroupsControllerTestCase :: testAction()

控制器测试用例与控制台烘烤和我使用从2.x的文档以下。

public function testIndex() { 
    $result = $this->testAction('/groups/index'); 
    debug($result); 
} 

GroupsControllerTest.php

<?php 
App::uses('GroupsController', 'Controller'); 


class TestGroupsController extends GroupsController { 

public $autoRender = false; 

public function redirect($url, $status = null, $exit = true) { 
    $this->redirectUrl = $url; 
} 
} 


class GroupsControllerTestCase extends CakeTestCase { 

public $fixtures = array('app.group'); 


public function setUp() { 
    parent::setUp(); 
    $this->Groups = new TestGroupsController(); 
    $this->Groups->constructClasses(); 
} 

public function tearDown() { 
    unset($this->Groups); 

    parent::tearDown(); 
} 

public function testIndex() { 
    $results = $this->testAction('/groups/index'); 
    debug($results); 
} 
..... 
+0

你能提供更多的信息吗?就像你的PHP版本和测试文件开头的几行一样? – 2012-03-30 15:09:01

+0

当然,运行PHP 5.3.6(MAMP)。我将用测试案例文件 – rossjha 2012-03-30 15:13:19

回答

2

我相信你的测试用例应该扩展ControllerTestCase,不CakeTestCase。

class GroupsControllerTestCase extends ControllerTestCase { 
    ... 
+0

更新我的问题!谢谢Ondrej – rossjha 2012-03-30 15:27:45

+0

不客气:) – 2012-03-30 15:29:30