Loading Zend-Framework Model in Phpunit Class - php

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.

Related

Ubuntu + Netbeans - Zend framework fatal error due to Include path

I'm experiencing a problem with my 'include' path on my fresh install of Zend framework. i'm running Ubuntu and using Netbeans. I installed Zend via the terminal and I have copied the appropriate files to my new project.
I am currently getting this while attempting to access localhost/demoZend/public
Warning: require_once(Zend/Application.php): failed to open stream: No such file or directory in /home/mastered/public_html/demoZend/public/index.php on line 18
Fatal error: require_once(): Failed opening required 'Zend/Application.php' (include_path='/home/mastered/public_html/demoZend/library:.:/opt/lampp/lib/php') in /home/mastered/public_html/demoZend/public/index.php on line 18
I have copied the 'Zend' folder with the framework into my project/library folder so the folder structure is /demoZend/library/Zend/
I have also changed the 'include' path in my php.ini from the advice of a tutorial. however this is where I have things confused.
The path reads:
include_path = ".:/usr/share/php:/usr/share/php/libzend-framework-php/"
in my apache2/php.ini aswell as my /etc/php5/cli/php.ini file.
My index.php file in my project reads as thus:
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// 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';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
I haven't changed that as the file paths seem ok.
I should also point out I have my web documents stored in my '~/public_html' directory, I have checked the permissions on my 'demoZend/library' folder and they have all restrictions off.
It sounds like you're following a tutorial for Zend Framework 1, but you've downloaded Zend Framework 2. There is no Zend/Application.php in ZF2, so that's why PHP isn't finding the file.
You can either head back to the ZF downloads page and grab the latest release of ZF1 (currently 1.12.3), or find a ZF2 tutorial and learn ZF2 instead. If you're just getting started with ZF, I'd go with the latter option.

PHPUnit & Zend Framework

I'm new to unit tests, i have been working on this tutorial i found on internet :
http://blog.fedecarg.com/2008/12/27/testing-zend-framework-controllers/
My problem is i simply can't execute the tests displayed in the tutorial!
C
:\wamp\www\portailmg\dev\tests>phpunit PHPUnit 3.7.21 by Sebastian
Bergmann.
Configuration read from C:\wamp\www\portailmg\dev\tests\phpunit.xml
Time: 0 seconds, Memory: 4.00Mb
No tests executed!
Generating code coverage report in HTML format ... done
C:\wamp\www\portailmg\dev\tests>
My bootstrap.php which is the only file i edited because i had the following error :
Notice: Zend_Loader::Zend_Loader::registerAutoload is deprecated as of
1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead in /www/zf-tutorial/library/Zend/Loader.php
I tried to fix this with that :
This is because you have the lines:
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
(or similar) somewhere in your bootstrap system.
The easiest solution is to change them to:
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('App_');
Where 'App_' is the name of a directory on your include path that has classes within it that follow the Zend Framework naming convention, so change it as appropriate and add more if you need them.
My bootstrap:
<?php
error_reporting( E_ALL | E_STRICT );
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
date_default_timezone_set('Europe/London');
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../applications'));
define('APPLICATION_ENV', 'loc');
define('LIBRARY_PATH', realpath(dirname(__FILE__) . '/../library'));
define('TESTS_PATH', realpath(dirname(__FILE__)));
$_SERVER['SERVER_NAME'] = 'http://localhost';
$includePaths = array(LIBRARY_PATH, get_include_path());
set_include_path(implode(PATH_SEPARATOR, $includePaths));
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('LIBRARY_PATH');
Zend_Session::$_unitTestEnabled = true;
Zend_Session::start();
?>
Thanks in advance for your help
Your setup looks okay, although if I remember correctly zend framework 1 will only work with >=3.5.x so maybe downgrading from 3.7 to 3.5 may do the trick. Do ensure your phpunit.xml file is setup properly and pointing to the tests bootstrap and not your application bootstrap. Also be sure to be following the unit testing name conventions. See http://phpunit.de/manual/3.5/en/index.html

Moving index.php out of application root in zend frame work

I am trying to change the path of index.php.
I have a boot strap zend structure.
So I created a new folder named newapp, its path is root path where our index.php lies.
Then I copied the index.php to newapp so that I can load the application from newapp directory.
But problem is that I can't load configuration file from index.php that I copied. It thorws error which is given below.
Fatal error: Uncaught exception 'Zend_Config_Exception' with message
'parse_ini_file(E:\xampp\htdocs\..../configs/application.ini) [<a href='function.parse-
ini-file'>function.parse-ini-file</a>]: failed to open stream: No such file or directory'
in E:\xampp\htdocs\ZendFramework-1.12.0\library\Zend\Config\Ini.php:182
Note my folder structure
- trunk
- index.php
- application
- bootstrap.php
- configs
- config.ini
- newapp
- index.php (copy of above)
My actual index.php is given below
<?php
ini_set('memory_limit', '-1');
set_time_limit(0);
defined('BASE_PATH')|| define('BASE_PATH', realpath(dirname(__FILE__)));
define('APPLICATION_PATH', BASE_PATH . '/application');
set_include_path('../../library1.12.0/'. get_include_path());
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->setFallbackAutoloader(true);
defined('APPLICATION_ENV')|| define('APPLICATION_ENV',(getenv
('APPLICATION_ENV') ? getenv('APPLICATION_ENV'): 'staging_mysql'));
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap();
$application->run();
What should I change in index.php ?
I tried change the path of config file as
APPLICATION_PATH . '/../../configs/application.ini'
but didn't work
- Zend library is available beacuse I have set path variable to it from
enviornment variable settings of windows.
I tried this also realpath(dirname(__FILE__))."/.."
But application is not loaded.
try adding
set_include_path(
APPLICATION_PATH.'/../library1.12.0'.PATH_SEPARATOR.
APPLICATION_PATH.'/../library1.12.0/Zend'
);
defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__)));
define('APPLICATION_PATH', BASE_PATH . '/application');
set_include_path('../../library1.12.0/'. get_include_path());
Should be this in newapp/index.php with the lines below
defined('BASE_PATH')|| define('BASE_PATH', realpath(dirname(__FILE__)));
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', BASE_PATH . '/../../application');
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library1.12.0'),
get_include_path()
)));
NOTE:
folder 'library1.12.0' shoould be in application folder level and Zend folder should be inside it. Hope this will help you, i have tested it and its working.

Zend Framework Error: Failed opening required 'Zend/Application.php'

I get the following error when I try to run the project created by Zend Framework. Its looking for Zend/Application.php and that is available in the directory that is in my include_path. I do have read permissions on the directory.
PHP Fatal error: require_once() [function.require]:
Failed opening required 'Zend/Application.php'
(include_path='/var/www/vhosts/moderncloud.net/om/library:.:/var/www/vhosts/moderncloud.net/om
/library:') in /var/www/vhosts/moderncloud.net/om/public/index.php on
line 24
<?php
// Define path to application directory
//defined('APPLICATION_PATH')
// || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', dirname(__FILE__) . '/../application');
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
('/var/www/vhosts/moderncloud.net/om/library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
SOLUTION:
I found it myself today. Its a problem with the option
"php_admin_value open_basedir" in my httpd configuration. I set it to
none and it started working. Alternatively, I guess I can append the Zend library
directory to the open_basedir option in my web server configuration instead of setting it to none.
Can you try replacing:
set_include_path(implode(PATH_SEPARATOR, array(
('/var/www/vhosts/moderncloud.net/om/library'),
get_include_path(),
)));
with
$siteRootDir = dirname($_SERVER['DOCUMENT_ROOT']);
set_include_path(
$siteRootDir . '/library' . PATH_SEPARATOR
. $siteRootDir . '/application' . PATH_SEPARATOR
. get_include_path()
);
Hope it works for you
If possible, remove the existing zend framework installation and install ZF using PEAR. It will be easier to update later on:
pear channel-discover zend.googlecode.com/svn
pear install zend/zend
It will also use PEAR's include_path, so it should solve your problem.
If you can't use pear, try to use relative path with your include path:
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
This problem generated due to :
Inside Public folder in index.php file.
or
Inside library folder :- Just check in library folder there is a folder of Zend present in library folder or not.If not present zend folder then download from zend framework and save in library folder.
=> In index.php copy the following code and replace it.
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// 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';
require_once 'library/Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();

ZEND Classes are not loading on Production server

I shifted the site from shared server to dedicated server but the site is not working correctly. I am getting the error as "Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'The PDO extension is required for this adapter but the extension is not loaded' in ";
Result for:
if (extension_loaded('pdo') and extension_loaded('pdo_mysql')) {
print "Success";
} else {
print "Failure";
}
is also false.
------Index File------
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// 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';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
Link of the site: http://voxsun.com
phpinfo of site: http://voxsun.com/public/info.php
Thanks,
Lalit
In the first line of your phpinfo() we can read:
'./configure' '--disable-pdo'
Well, it's self-explanatory.
If you compiled PHP yourself, I really advise you to use your package manager to do so (aptitude, yum, etc.), it'll ease your system upgrade and avoid you to compile it hand each time you need to update PHP.
Do it only if you've very good reasons.
From the you're info.php ... Configure Command './configure' '--disable-pdo' so put it simple, php wasn't compiled with pdo in mind .
One option would be to try and load the extensions manualy in public/index.php at the start of you're script ( i don't expect it to work but it's worth giving it a try ) :
dl('pdo.so');
dl('pdo_mysql.so');
PHP: dl - Loads a PHP extension at runtime

Categories