Yii Framework Forum: PHP Unit Testing Problems With Database connection - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

PHP Unit Testing Problems With Database connection PHP Unit Testing Problems With Database connection Rate Topic: -----

#1 User is offline   paul_tiberius 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 03-September 12

Posted 03 September 2012 - 07:40 AM

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
0

#2 User is offline   yugene 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 492
  • Joined: 08-August 09

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?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users