How to use phpunit with DBUnit on IBM DB2?

218 views Asked by At

i'm having some problems while trying to use PHPUnit_Extensions_Database_TestCase on IBM Db2. I've tried different solutions:

1. with a DBAL connection in the getConnection() method:

final public function getConnection() {

    $options = array(
      'i5_naming' => DB2_I5_NAMING_ON,
      'DB2_ATTR_CASE' => DB2_CASE_LOWER
    );

    $driver = 'ibm_db2';
    $ConnParm = array(
      'driver' => $driver,
      'dbname' => $hostDB,
      'host' => $tcphost,
      'user' => $un,
      'password' => $pw,
      'driverOptions' => $options
    );

    $this->connDB = DriverManager::getConnection($ConnParm);

    $this->conn = $this->createDefaultDBConnection($this->connDB, $ConnParm['dbname']);

    return $this->conn;
   }

having this exception: Argument 1 passed to PHPUnit_Extensions_Database_TestCase::createDefaultDBConnection() must be an instance of PDO, instance of Doctrine\DBAL\Connection given,

2. with PDO connection 
 final public function getConnection()
    {
        if ($this->conn === null) {
            if (self::$pdo == null) {
                self::$pdo = new PDO( $GLOBALS['DB_DSN'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD'] );
            }
            $this->conn = $this->createDefaultDBConnection(self::$pdo, $GLOBALS['DB_DBNAME']);
        }

        return $this->conn;
    }

execption: PHPUnit_Extensions_Database_Exception: Specified class for ibm driver (PHPUnit_Extensions_Database_DB_MetaData_Ibm) does not exist.

3 by creating the Ibm.php class inside:
phpunit/dbunit/PHPUnit/Extensions/Database/DB/Meatadata/Ibm.php

adding the line: 
'ibm' => 'PHPUnit_Extensions_Database_DB_MetaData_Ibm' inside $metaDataclassMap in Extensions/Database/DB/MetaData.php

adding the line :
'phpunit_extensions_database_db_metadata_ibm' => '/Extensions/Database/DB/MetaData/Ibm.php' inside dbunit/PHPUnit/Extensions/Database/Autoload.php

exception: PHPUnit_Extensions_Database_Exception: Specified class for ibm driver (PHPUnit_Extensions_Database_DB_MetaData_Ibm) does not exist.

Is there some one that knows how can i test the IBM DB2 database with PHPUnit and DBUnit (by using getDataSet,assertDataSetsEqual() .. )?

Thank's a lot

More Details:

I've copied the Oci.php and created the Ibm.php script from it ,in the folder :

phpunit/dbunit/PHPUnit/Extensions/Database/DB/Meatadata/

Inside the Ibm.php script I've declared the class: PHPUnit_Extensions_Database_DB_MetaData_Ibm with this methods:

getTableNames()
getTableColumns()
getTablePrimaryKeys()
loadColumnInfo()

In this moment I'm not concentrating on the methods content. I will adapte them to the DB2 SQL later .

After doing this i've added the element: 'ibm' => 'PHPUnit_Extensions_Database_DB_MetaData_Ibm' inside $metaDataclassMap array in Extensions/Database/DB/MetaData.php and into the autoload:

dbunit/PHPUnit/Extensions/Database/Autoload.php

i've added the element :

'phpunit_extensions_database_db_metadata_ibm' => '/Extensions/Database/DB/MetaData/Ibm.php'.

Now i'm having this Error:

1) DeliveredOrdersTest::testIfGetsDataSet PHPUnit_Extensions_Database_Exception: Specified class for ibm driver (PHPUnit_Extensions_Database_DB_MetaData_Ibm) does not exist.

while running this test(the deliveredOrdersXmlFixture.xml is a standard XML DataSet) :

class DeliveredOrdersTest extends PHPUnit_Extensions_Database_TestCase {
  // only instantiate pdo once for test clean-up/fixture load
    static private $pdo = null;

    // only instantiate PHPUnit_Extensions_Database_DB_IDatabaseConnection once per test
    private $conn = null;

    final public function getConnection()
    {
        if ($this->conn === null) {
            if (self::$pdo == null) {
                self::$pdo = new PDO( $GLOBALS['DB_DSN'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD'] );
            }
            $this->conn = $this->createDefaultDBConnection(self::$pdo, $GLOBALS['DB_DBNAME']);
        }

        return $this->conn;
    }

  /**
   * @return PHPUnit_Extensions_Database_DataSet_IDataSet
   */
  public function getDataSet() {
    return $this->createXMLDataSet(dirname(__FILE__) . '/_files/deliveredOrdersXmlFixture.xml');
  }

  public function testIfGetsDataSet() {
    // empty test, in order to have the getDataSet call
    }
}

What am I missing? Where do I have to specify my new PHPUnit_Extensions_Database_DB_MetaData_Ibm class in order to let PHPUnit to find it? Am I so far from getting any kind of Error from the test execution? Thank's in advance.

0

There are 0 answers