Hi
I am trying to write database test cases to run with phpunit and am getting the following error :-
There was 1 error:
1) DbTest::testConnection
CDbException: CDbConnection failed to open the DB connection.
/opt/lampp/htdocs/yii_root/framework/db/CDbConnection.php:388
/opt/lampp/htdocs/yii_root/framework/db/CDbConnection.php:331
/opt/lampp/htdocs/yii_root/framework/db/CDbConnection.php:309
/opt/lampp/htdocs/yii_root/framework/base/CModule.php:388
/opt/lampp/htdocs/yii_root/framework/base/CModule.php:104
/opt/lampp/htdocs/trackstar/protected/tests/unit/DbTest.php:6
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
Additional Information:
I am running Yii on xampp under linux mint and am doing the tutorials in the book "Agile Web Application Development with Yii1.1 and PHP5.
DbTest.php
<?php
class DbTest extends CTestCase
{
public function testConnection()
{
$this->assertNotEquals(NULL, Yii::app()->db);
My test config file is test.php
<?php
return CMap::mergeArray(
require(dirname(__FILE__).'/main.php'),
array(
'components'=>array(
'fixture'=>array(
'class'=>'system.test.CDbFixtureManager',
),
// uncomment the following to provide test database connection
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=trackstar_dev;',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'xxxx',
'charset' => 'utf8',
),
),
)
);
I have tried to implement suggestions but to no avail, can anyone help?
PQUL
Page 1 of 1
PHP Unit Testing Problems With Database connection PHP Unit Testing Problems With Database connection
#2
Posted 03 September 2012 - 09:32 PM
Try to get rid of the last
;in your connection string (works fine for me, but have never seen it in docs examples). Also please check out that you definitely have database trackstar_dev. Also, might be you need to connect to 127.0.0.1 - depends on you mysql installation. Do you use `localhost` for any working site?
Share this topic:
Page 1 of 1

Help













