Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-20-2008, 07:10 AM
Junior Member
 
Join Date: Mar 2008
Posts: 8
Default Can't get the phpUnit to work

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(213213"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());
    }
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-22-2008, 02:05 PM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 122
Default

You need to add the application directory you the include path. Put all the include paths from your bootstrap in the AllTest.php so it can find all the site pages.
__________________
Zend Framework Resources: Zend Webinars | Reference Manual | API Docs | Books | FreeNode: #zftalk
Getting Started Tutorials: Getting started with ZF | Getting started with Zend Auth
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:11 PM.