all:
doctrine:
class: sfDoctrineDatabase
param:
dsn: 'mysql:host=localhost;dbname=ms'
username: ms
password: xxx
test:
doctrine:
class: sfDoctrineDatabase
param:
dsn: 'mysql:host=localhost;dbname=ms'
username: ms
password: xxx
...
位于(test/unit/MSTest.php)的测试文件如下所示:
require_once dirname(__FILE__).'/../bootstrap/unit.php';
$a = new Article();
$a->setHeadline("Article Headline");
$a->save();
C:\phpworkspace\ms>php test/unit/MSTest.php
Fatal error: Uncaught exception 'Doctrine_Connection_Exception' with message 'There is no open connection' in C:\phpworkspace\ms\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Manager.php:662
Stack trace:
#0 C:\phpworkspace\ms\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Manager.php(557): Doctrine_Manager->getCurrentConnection()
#1 C:\phpworkspace\ms\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Core.php(1095): Doctrine_Manager->getConnectionForComponent('Article')
#2 C:\phpworkspace\ms\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Record.php(219): Doctrine_Core::getTable('Article')
#3 C:\phpworkspace\ms\test\unit\UniversalDemoTest.php(15)
: Doctrine_Record->__construct()
#4 {main}
thrown in C:\phpworkspace\ms\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Manager.php on line 662
我在谷歌上搜索了一下,似乎所有的提示都指向database.yml test:environment,这个环境(见上图)。我在命令行上测试了username/password/db name,用户确实有效。这个
other solution described here
替换unit.php中
$configuration = ProjectConfiguration::hasActive() ?
ProjectConfiguration::getActive() :
new ProjectConfiguration(realpath($_test_dir.'/..'));
$configuration = ProjectConfiguration::getApplicationConfiguration(
'frontend', 'test', true
);
我正在用symfony1.4(XAMPP)运行php5.3.1、mysql 5.1.41。