cakephp ControllerTest
cakephp, testing
Solution
Try adding the following to the top of your ArticlesController file:
App::uses('AppController', 'Controller');
Problem
I'm a noob trying to write a ControllerTest for the Blog Tutorial of the cakephp book. Completing this task, I searched for a good example, which I can adapt. The book offers the following example: http://book.cakephp.org/2.0/en/development/testing.html#testing-controllers So I created an ArticlesController.php file in /app/Controller/ and a ArticlesControllerTest.php in /app/Test/Case/Controller/ The content of my ArticlesController.php is: ``` <?php class ArticlesController extends ControllerTestCase { //public $fixtures = array('app.article'); public function testIndex() { $result = $this->testAction('/articles/index'); debug($result); } public function testIndexShort() { $result = $this->testAction('/articles/index/short'); debug($result); } public function testIndexShortGetRenderedHtml() { $result = $this->testAction( '/articles/index/short', array('return' => 'contents') ); debug($result); } public function testIndexShortGetViewVars() { $result = $this->testAction( '/articles/index/short', array('return' => 'vars') ); debug($result); } public function testIndexPostData() { $data = array( 'Article' => array( 'user_id' => 1, 'published' => 1, 'slug' => 'new-article', 'title' => 'New Article', 'body' => 'New Body' ) ); $result = $this->testAction( '/articles/index', array('data' => $data, 'method' => 'post') ); debug($result); } ``` } And the content of my ArticlesController.php is: ``` <?php class ArticlesControllerTest extends ControllerTestCase { public $fixtures = array('app.article'); public function testIndex() { $result = $this->testAction('/articles/index'); debug($result); } public function testIndexShort() { $result = $this->testAction('/articles/index/short'); debug($result); } public function testIndexShortGetRenderedHtml() { $result = $this->testAction( '/articles/index/short', array('return' => 'contents') ); debug($result); } public function testIndexShortGetViewVars() { $result = $this->testAction( '/articles/index/short', array('return' => 'vars') ); debug($result); } public function testIndexPostData() { $data = array( 'Article' => array( 'user_id' => 1, 'published' => 1, 'slug' => 'new-article', 'title' => 'New Article', 'body' => 'New Body' ) ); $result = $this->testAction( '/articles/index', array('data' => $data, 'method' => 'post') ); debug($result); } } ``` I copied this codes from the book and outcommented the fixtures. Runing the test gave me the following error: Error: Class 'AppController' not found File: /Applications/MAMP/htdocs/cake/app/Controller/ArticlesController.php Line: 3 Dafaq is wrong? Thxs!