I want to call my zend-framework model and use there functions in AuthenticationControllerTest.php
but I am getting error when i run it from terminal.
- -MyZendproject
- -application
-model
-testmodel
- +public
- -tests
- aplication
- controller
- .AuthenticationControllerTest.php
Here is my AuthenticationControllerTest.php
file
<?php
require_once `PHPUnit/Framework/TestCase.php`;
defined(`APPLICATION_PATH`)
|| define(`APPLICATION_PATH`, realpath(dirname(__FILE__) . `/../application`));
// Define application environment
defined(`APPLICATION_ENV`) || define(`APPLICATION_ENV`, `tests`);
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR,
array(realpath(APPLICATION_PATH . `../../../library`), get_include_path())));
// Zend_Application
require_once `Zend/Application.php`;
$application = new Zend_Application(
APPLICATION_ENV,
realpath(APPLICATION_PATH .`configs/application.ini`)
);
class AuthenticationControllerTest extends PHPUnit_Framework_TestCase
{
public function testLoginRetriespLogin() {
$testmodel = new Model_testmodel_Object();//my model
}
}
but when run it from terminal "phpunit AuthenticationControllerTest" it give me error:
$ phpunit AuthenticationControllerTest
..FPHP Fatal error: Class 'Model_testmodel_Object' not found in /var/www/versioned/pm160form/tests/application/controllers/AuthenticationControllerTest.php on line 146
Looks like your test suit folder is not resolving towards the actual application folder. See how you have
|| define(`APPLICATION_PATH`, realpath(dirname(__FILE__) . `/../application`));
but your dirname is currently pointing to the test/application/controller directory which, of course, does not have your actual application. Try pointing the application folder that is under the top root instead,
|| define(`APPLICATION_PATH`, realpath(dirname(__FILE__) . `/../../../application`));
Also, take care to follow the standard of using PHP Unit in Zend Framework as described at http://framework.zend.com/manual/1.12/en/zend.test.phpunit.html . The framework needs to be fully bootstraped before the autoloader can work.