I am trying to test the controllers, but it dosent find the controller. I have tried diffrent ways but i get same error.
Get this Error
Code:
1) testControllerWorking(indexControllerTests)
Zend_Controller_Dispatcher_Exception: Invalid controller specified (error)
F:\wamp\www\zend\library\Zend\Controller\Front.php:914
F:\wamp\www\zend\tests\application\default\controllers\indexControllerTests.php:
67
Structure of project is this
Code:
-application
--default
---controllers
----indexController.php
---models
---views
-html
--index.php
-library
--zend
--my
-tests
-AllTests.php
-application
--default
---controllers
----indexControllerTest.php
---models
AllTests.php code
PHP Code:
<?php
if (!defined('ROOT_DIR')) {
define('ROOT_DIR', dirname(dirname(__FILE__)));
}
$paths = array(
'',
ROOT_DIR . '\library',
get_include_path()
);
$paths = implode('.' . PATH_SEPARATOR, $paths);
set_include_path($paths);
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
//require_once 'PHPUnit/TextUI/TestRunner.php';
require_once 'application/default/controllers/indexControllerTests.php';
/**
* Static test suite.
*/
class AllTests {
/**
* Constructs the test suite handler.
*/
public static function main() {
PHPUnit_TextUI_TestRunner::run(self::suite(), array());
}
public static function suite() {
$suite = new PHPUnit_Framework_TestSuite();
$suite->setName('SampleApp');
$suite->addTestSuite('indexControllerTests');
return $suite;
}
}
IndexControllerTests.php
PHP Code:
<?php
require_once 'PHPUnit/Framework.php';
require_once 'Zend/Loader.php';
//require_once 'Registry.php';
if (!defined('ROOT_DIR')) {
define('ROOT_DIR', dirname(dirname(dirname(dirname(dirname(__FILE__))))));
}
/**
* IndexController test case.
*/
class indexControllerTests extends PHPUnit_Framework_TestCase {
private $front;
function setUp() {
Zend_Loader::registerAutoload();
$this->front = Zend_Controller_Front::getInstance();
$this->front->setControllerDirectory(ROOT_DIR . 'application\default\controllers\\');
$this->front->resetInstance();
$this->front->returnResponse(true);
}
function testHasTheFrontControllerInstanceInRegistry() {
/*
$front = Zend_Registry::get('front');
$this->assertTrue($front instanceof Zend_Controller_Front);
$this->markTestSkipped('Test vahele');
*/
}
function testDoesTheRegistryWorks() {
$reg = Zend_Registry::getInstance();
$reg->set('db', 'Database');
//$this->assertTrue(false, '.' . $reg->get('db') . '.');
$this->assertEquals($reg->get('db'), 'Database');
}
function testIsItEqual() {
$this->assertEquals(213, 213, "It is not equal!");
}
function testControllerWorking() {
$request = new Zend_Controller_Request_Http();
$request->setControllerName('index');
$request->setActionName('index');
$response = $this->front->dispatch($request);
$this->assertFalse($response->isException());
$this->assertContains('index', $response->getBody());
}
}