Hi,
Do you using Windows + Apache?
Locate in your HD all php.ini files.
Depend what distribution of Apache+PHP you are using, the php.ini will apear on some places.
SomeDir\php\php.ini
Apache\bin\php.ini
WinDir\php.ini
A simple way to resolve this is open every file and configure (or copy).
if the problem still there, copy php.ini to WinDir (if not exist).
Another way is to remove all php.ini except in WinDir.
Remember Always do a backup.
On Linux you can do similar thing.
When running by apache module and running by command line (like phpunit) some search paths difers.
Of course, this is a funcional way, but not the best.
Best regards,
Luiz Fernando
Do you using Windows + Apache?
Locate in your HD all php.ini files.
Depend what distribution of Apache+PHP you are using, the php.ini will apear on some places.
SomeDir\php\php.ini
Apache\bin\php.ini
WinDir\php.ini
A simple way to resolve this is open every file and configure (or copy).
if the problem still there, copy php.ini to WinDir (if not exist).
Another way is to remove all php.ini except in WinDir.
Remember Always do a backup.
On Linux you can do similar thing.
When running by apache module and running by command line (like phpunit) some search paths difers.
Of course, this is a funcional way, but not the best.
Best regards,
Luiz Fernando
De: Mike Bronner <mike.bronner@gmail.com>
Para: fw-db@lists.zend.com
Enviadas: Quinta-feira, 15 de Janeiro de 2009 22:39:58
Assunto: [fw-db] ZendFramework Application vs TestCase Connection
Hi All,
Not quite sure where to start. I guess I'll list the problems I'm having: my unit tests will not connect to the database (using the same bootstrap and config.ini file as the application), while the application has no problem connecting. It seems as if the unit tests run on a different php.ini file than the application.
My config file (obfuscated, of course):
[default]
database.adapter = PDO_MYSQL
database.params.host = xxx.xxx.xxx.xxx
database.params.username = me
database.params.password = mypassword
database.params.dbname = test_data
This works just dandy for the modules under the application folder. When I try to run a unit test with this I get:
The mysql driver is not currently installed.
Doing a phpinfo() dump within the unit test does indeed show that the MYSQL drivers are loaded, and the bootstrap file is getting run properly and set the correct values in Zend_Db_Table_Abstract::setDefaultAdapter.
For completeness, here is my bootstrap file:
class Bootstrap
{
public function __construct($config_section = 'production')
{
define('ROOT_DIR', dirname(dirname(__FILE__)));
define('APPLICATION_PATH', dirname(__FILE__));
define('APPLICATION_ENVIRONMENT', 'development');
set_include_path
(
get_include_path() .
PATH_SEPARATOR . ROOT_DIR . '/library/' .
PATH_SEPARATOR . APPLICATION_PATH . '/default/models/'
);
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
Zend_Registry::set('configSection', $config_section);
$config = new Zend_Config_Ini(APPLICATION_PATH . '/config.ini', $config_section);
Zend_Registry::set('config', $config);
date_default_timezone_set($config->date_default_timezone);
$db = Zend_Db::factory($config->database);
Zend_Db_Table_Abstract::setDefaultAdapter($db);
Zend_Registry::set('db', $db);
}
public function configureFrontController()
{
$frontController = Zend_Controller_Front::getInstance();
$frontController->setControllerDirectory(APPLICATION_PATH . '/default/controllers/');
}
public function runApp()
{
$this->configureFrontController();
$frontController = Zend_Controller_Front::getInstance();
$frontController->dispatch();
}
}
and here my unit test:
require_once dirname(__FILE__) . '/../../../TestConfiguration.php';
require_once '../../../../application/default/models/Users.php';
class UsersTest extends PHPUnit_Framework_TestCase
{
public function setup()
{
TestConfiguration::setupDatabase();
}
public function testFetchAll()
{
$users = new Users();
$this->assertSame(4, $users->fetchAll()->count());
}
public function testFetchLatestShouldFetchLatestEntry()
{
$usersFinder = new Users();
$users = $usersFinder->fetchLatest(1);
$this->assertSame(1, $users->count());
$user = $users->current();
$this->assertSame(4, (int)$user->id);
}
}
And the TestConfiguration class:
TestConfiguration::setup();
class TestConfiguration
{
static $bootstrap;
static function setup()
{
require_once dirname(__FILE__) . '/../application/bootstrap.php';
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__ . '/../library/')));
self::$bootstrap = new Bootstrap('testing');
}
static function setupDatabase()
{
$db = Zend_Registry::get('db');
$db->query(<<<EOT
DROP TABLE IF EXISTS users
EOT
);
}
}
And the Users class:
class Users extends Zend_Db_Table_Abstract
{
protected $_name = 'users';
protected $_rowClass = 'User';
function __get($key)
{
if (method_exists($this, $key)) {return $this->$key();}
else {return parent::__get($key);}
}
function fetchLatest($count = 10)
{
return $this->fetchAll(null, 'date_created DESC', $count);
}
}
I'm not sure where to go from here. My thought is that since the application is working just fine, perhaps PHPUNIT is not configured correctly, or reading a different PHP.INI file (eventhough I did a global search for all PHP.INI and edited them accordingly to load all MYSQL drivers).
Thanks for any help!
-Mike
Veja quais são os assuntos do momento no Yahoo! + Buscados: Top 10 - Celebridades - Música - Esportes
没有评论:
发表评论