I guess I should have incorporated my System setup in the initial email.
Ubuntu 8.10
Zend Studio 6.1
Zend Framework 1.7.2
Flex 3.0 (Linux Alpha) plugin for Eclipse
Zend Core
Doing some more research I realized that PHPUnit in Zend Studio is NOT using the same php.ini file as Zend Core does. What's further troubling is that is seems to create a temporary php.ini file in the /tmp folder every time PHPUnit runs (I'm using the PHPUnit that comes with Zend Studio, I have not made a manual install with PEAR or APT-GET. This leads my to believe that this version of PHPUnit has a built-in, dynamic php.ini creation routine that runs everytime a test case or suite is executed.
Now, I did figure out where some library files are stored that are reference from php.ini, and have copied over the PDO and MYSQL libraries to that location. Now the libraries are loading, and I no longer receive the below error. Unfortunately now, however, the client API version shows 3.x, whereas a 5.x library is required (it throws a connection error). I copied the libraries (*.so files) from the Zend Core php extensions folder. I don't have this issue when running the app, so again I think it's an issue with the PHPUnit configuration in Zend Studio.
Again, I've reached what seems to be a show-stopper. How are you guys able to connect to MYSQL in your PHPUnit tests using ZendStudio?
Thanks again for any information or ideas you can provide.
-Mike
On Fri, Jan 16, 2009 at 3:19 AM, Luiz Fernando <kgbfernando@yahoo.com.br> wrote:
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
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
--
Celebrate Liberty, Freedom, and Rights at http://www.theconstitutionalist.us.
没有评论:
发表评论