2008年9月13日星期六

[fw-mvc] Help needed setting up a test unit (Zend_Test_PHPUnit_ControllerTestCase)

Hi everyone !
I'm banging my head against the walls trying to setup correctly a test unit with
Zend_Test_PHPUnit_ControllerTestCase.
 
When I run phpunit on the command line I get
 
testCallWithoutActionShouldPullFromIndexAction
Failed asserting last controller used was 'user'
 
I don't understand why it's not working.
Any help really appreciated, I've spent those last 2 days trying to make this work.
 
Thanks
 
Here are my files :
 
UserControllerTest.php :
------------------------- start ----------------------------

require_once 'TestHelper.php';

 

class UserControllerTest extends Zend_Test_PHPUnit_ControllerTestCase

{

public $bootstrap = '/usr/local/www/html/index.php';

public function setUp()

{

// Execute any startup code here

defined('DISPATCH_FRONT_CONTROLLER') or define('DISPATCH_FRONT_CONTROLLER', false);

parent::setUp();

}

public function testCallWithoutActionShouldPullFromIndexAction()

{

//$this->fail(var_export($this->frontController->getControllerDirectory(), 1));

$this->dispatch('/user');

// $this->assertResponseCode(200);

$this->assertController('user');

$this->assertAction('index');

}

}
 
------------------------- end ----------------------------
 
My /usr/local/www/html/index.php (it's messy, don't pay attention):
 
------------------------- start ----------------------------
 

defined('DISPATCH_FRONT_CONTROLLER') or define('DISPATCH_FRONT_CONTROLLER', true);

 

 

require_once "Zend/Loader.php";

Zend_Loader::loadClass('Zend_Controller_Front');

Zend_Loader::registerAutoload();

 

// Configuration file

$config = new Zend_Config_Ini('../html/config.ini', 'development');

Zend_Registry::set('config', $config);

// Adding libraries

set_include_path('../application/includes' . PATH_SEPARATOR . get_include_path());

require_once '../application/DatabaseObject/UserDatabaseObject.php';

require_once '../application/Profile/User.php';

require_once '../application/Forms/CreateUserForm.php';

require_once '../application/Forms/UserLoginForm.php';

require_once '../application/Forms/newPasswordForm.php';

 

 

// Database object creation

$params = array(

'host' => $config->database->hostname,

'username' => $config->database->username,

'password' => $config->database->password,

'dbname' => $config->database->database

);

$db = Zend_Db::factory($config->database->type, $params);

Zend_Registry::set('db', $db);

 

// setting the logger

$logger = new Zend_Log(new Zend_Log_Writer_Stream($config->logging->file));

Zend_Registry::set('logger', $logger);

 

// setting the layout

Zend_Layout::startMvc(array(

'layoutPath' => '../application/layouts'

));

 

// Layouts & views (Let's assign our imaginary base url in the view so we can refer to it:

$view = Zend_Layout::getMvcInstance()->getView();

 

 

// Authentication

$auth = Zend_Auth::getInstance();

$auth->setStorage(new Zend_Auth_Storage_Session()); 

 

// Initializing zend

$front = Zend_Controller_Front::getInstance();

$front->setControllerDirectory(dirname(dirname(__FILE__)) . '/application/controllers')

->setBaseUrl($config->baseUrl);

//$front->registerPlugin(new CustomControllerAclManager($auth));

$front->throwExceptions(true);

if (DISPATCH_FRONT_CONTROLLER)

{

$front->dispatch();

}

------------------------- end ----------------------------
 
And finally my TestHelper.php
 
------------------------- start ----------------------------
/*

* Start output buffering

*/

ob_start();

/*

* Set error reporting to the level to which code must comply.

*/

error_reporting( E_ALL | E_STRICT );

/*

* Set default timezone

*/

date_default_timezone_set('GMT');

/*

* Testing environment

*/

define('APPLICATION_ENV', 'testing'); 

 

require_once 'PHPUnit/Framework.php';

require_once 'PHPUnit/Framework/Constraint.php';

/*

* Determine the root, library, tests, and models directories

*/

$root = realpath(dirname(__FILE__) . '/../');

$library = $root . '/application/includes';

$tests = $root . '/tests';

$models = $root . '/application/DatabaseObject';

$controllers = $root . '/application/controllers';

/*

* Prepend the library/, tests/, and models/ directories to the

* include_path. This allows the tests to run out of the box.

*/

$path = array(

$library,

$tests,

$models,

$controllers,

get_include_path()

);

set_include_path(implode(PATH_SEPARATOR, $path));

/**

* Register autoloader

*/

$path = '/usr/local/share/ZendFramework/library/';

set_include_path(get_include_path() . PATH_SEPARATOR . $path);

require_once '/usr/local/share/ZendFramework/library/Zend/Loader.php';

Zend_Loader::registerAutoload();

/**

* Store application root in registry

*/

Zend_Registry::set('testRoot', $root);

Zend_Registry::set('testBootstrap', $root . '/html/index.php');

 

/*

* Unset global variables that are no longer needed.

*/

 

 

 
 
 
 
 


Appelez vos amis de PC à PC -- C'EST GRATUIT Téléchargez Messenger, c'est gratuit !

没有评论: