tags:

views:

276

answers:

0

I use PHPUnit DataBase to test some class using MDB2.

All is well, since I encounter the second test, which returns an error:

Caught exception: Object of class MDB2_Error could not be converted to string

When I place the second test in place of the first one, the new first test is OK, but the second one returns the same error! And the next ones also!

Maybe the MDB2 connection is closed after the first test?

Here is my constructor:

public function __construct()
{
    $this->pdo = new PDO('connectionstring', 'user', 'passwd');
    try {
        $this->mdb2 = new MyDBA($this->dsn);
    }
    catch (Exception $e) {
        error_log(' __construct Caught exception: '.$e->getMessage());
    }
}

MyDBA returns a singleton. No exception is raised inside the constructor...

Here are the two first tests:

public function testTranslationAdd()
{
    try {
        $id = $this->mdb2->addTranslation("This is the second english translation.","en");
    }
    catch (Exception $e) {
        error_log(' testTranslationAdd Caught exception: '.$e->getMessage());
    }

    $xml_dataset = $this->createFlatXMLDataSet(dirname(__FILE__).'/state/twotranslations.xml');
    $this->assertDataSetsEqual($xml_dataset,
                               $this->getConnection()->createDataSet(array("translation")));
}

public function testTranslationGet()
{
    try {
        $text = $this->mdb2->getTranslation(1,"en");
    }
    catch (Exception $e) {
        error_log(' testTranslationGet Caught exception: '.$e->getMessage());
    }

    $this->assertEquals("This is the first english translation.",$text);
}