/**
  * Loads & parses the schema SQL files.
  */
 protected static function loadStatements()
 {
     $schema = CREOLE_TEST_BASE . '/etc/db/sql/' . self::$dsn['phptype'] . '/creoletest-schema.sql';
     $data = CREOLE_TEST_BASE . '/etc/db/sql/' . self::$dsn['phptype'] . '/creoletest-data.sql';
     self::$schemaStatements = SQLStatementExtractor::extractFile($schema);
     self::$dataStatements = SQLStatementExtractor::extractFile($data);
 }
 /**
  * Test an ASSOC fetch with a connection that has the Creole::NO_ASSOC_LOWER flag set.
  */
 public function testFetchmodeAssocNoChange()
 {
     $exch = DriverTestManager::getExchange('ResultSetTest.ALL_RECORDS');
     $conn2 = Creole::getConnection(DriverTestManager::getDSN(), Creole::NO_ASSOC_LOWER);
     DriverTestManager::initDb($conn2);
     $rs = $conn2->executeQuery($exch->getSql(), ResultSet::FETCHMODE_ASSOC);
     $rs->next();
     $keys = array_keys($rs->getRow());
     $this->assertEquals("PRODUCTID", $keys[0], 0, "Expected to find uppercase column name for Oracle.");
     $rs->close();
 }
 /**
  * Test an ASSOC fetch with a connection that has the Creole::NO_ASSOC_LOWER flag set.
  *
  * NOTE: This parent method for this test opens a second connection in
  *       order to test the Creole::NO_ASSOC_LOWER flag. I had to override
  *       this because the ODBC driver I was testing with is very sensitive
  *       to having multiple connections open. In particular, I couldn't drop
  *       a database table (via DriverTestManager::initDb()) from the second
  *       connection while the first was still open.
  */
 public function testFetchmodeAssocNoChange()
 {
     if ($this->conn->getAdapter()->preservesColumnCase()) {
         $exch = DriverTestManager::getExchange('ResultSetTest.ALL_RECORDS');
         $dsn = DriverTestManager::getDSN();
         $this->conn->close();
         $this->conn->connect($dsn, Creole::NO_ASSOC_LOWER);
         DriverTestManager::initDb($this->conn);
         $rs = $this->conn->executeQuery($exch->getSql(), ResultSet::FETCHMODE_ASSOC);
         $rs->next();
         $keys = array_keys($rs->getRow());
         $this->assertEquals("ProductID", $keys[0], 0, "Expected to find mixed-case column name.");
         $rs->close();
         $this->conn->close();
         $this->conn->connect($dsn);
     }
 }
 public function testGetId()
 {
     // propel (which generated the SQL dumps) has
     // convention of creating sequences w/ namelike tablename_seq
     // so we'll use that here.
     $exch = DriverTestManager::getExchange('IdGeneratorTest.getId.INIT');
     $rs = $this->conn->executeQuery($exch->getSql(), ResultSet::FETCHMODE_NUM);
     $rs->next();
     $max = $rs->getInt(1);
     $keyInfo = 'idgentest_seq';
     if ($this->idgen->getIdMethod() === IdGenerator::SEQUENCE) {
         $exch = DriverTestManager::getExchange('IdGeneratorTest.getId.SEQUENCE');
         $id = $this->idgen->getId($keyInfo);
         $stmt = $this->conn->prepareStatement($exch->getSql());
         $stmt->executeUpdate(array($id, 'Test'));
     } else {
         $exch = DriverTestManager::getExchange('IdGeneratorTest.getId.AUTOINCREMENT');
         $stmt = $this->conn->prepareStatement($exch->getSql());
         $stmt->executeUpdate(array('Test'));
         $id = $this->idgen->getId($keyInfo);
     }
     $this->assertEquals($max + 1, $id, 0, "Next id was not max + 1");
 }
    $dsn = $argv[1];
}
$testSuite = new PHPUnit2_Framework_TestSuite($dsn);
// ----------------------------------------------------------------------------
// TESTS ----------------------------------------------------------------------
// ----------------------------------------------------------------------------
$timer = new Benchmark_Timer();
$timer->start();
// (1) Add Generic (non-Driver) Tests
// ----------------------------------
require_once 'creole/CreoleTest.php';
$testSuite->addTestSuite(new ReflectionClass('CreoleTest'));
require_once 'creole/util/sql/SQLStatementExtractorTest.php';
$testSuite->addTestSuite(new ReflectionClass('SQLStatementExtractorTest'));
// (2) Driver Tests
// ----------------
include_once 'creole/drivers/DriverTestManager.php';
print "--------------------------------------\n";
print "| Running driver tests               |\n";
print "--------------------------------------\n";
$timer->setMarker("start driver tests");
print "DSN: " . $dsn . "\n\n";
print "[It is safe to ignore any errors related to dropping nonexistant tables.]\n\n";
try {
    DriverTestManager::addSuite($testSuite, $dsn);
    PHPUnit2_TextUI_TestRunner::run($testSuite);
} catch (Exception $e) {
    print "Could not add suite for " . $dsn . ": " . $e->getMessage();
}
$timer->stop();
$timer->display();
 /**
  * Construct the class.  This is called before every test (method) is invoked.
  */
 public function __construct()
 {
     $this->conn = DriverTestManager::getConnection();
 }
 /**
  * Make sure that get() and getString() are returning properly rtrimmed results.
  */
 public function testTrimmedGet()
 {
     $exch = DriverTestManager::getExchange('ResultSetTest.setString.RTRIM');
     $stmt = $this->conn->prepareStatement($exch->getSql());
     $stmt->setString(1, "TEST    ");
     $stmt->setInt(2, 1);
     $stmt->executeUpdate();
     $stmt->close();
     $exch = DriverTestManager::getExchange('ResultSetTest.getString.RTRIM');
     $stmt = $this->conn->prepareStatement($exch->getSql());
     $stmt->setInt(1, 1);
     $rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM);
     $rs->next();
     $this->assertEquals("TEST", $rs->getString(1));
     $stmt->close();
     $rs->close();
 }
 /**
  * Construct the class.  This is called before every test (method) is invoked.
  */
 public function __construct()
 {
     $this->conn = DriverTestManager::getConnection();
     $this->dbi = $this->conn->getDatabaseInfo();
 }
 public function testSetTime()
 {
     // 1) set the value
     $exch = DriverTestManager::getExchange('PreparedStatementTest.setTime');
     $stmt = $this->conn->prepareStatement($exch->getSql());
     $now = time();
     // by defnition unix timestamps are in UTC
     $stmt->setInt(1, 1);
     $stmt->setTime(2, $now);
     $stmt->executeUpdate(ResultSet::FETCHMODE_NUM);
     $stmt->close();
     // 2) fetch the value
     $exch = DriverTestManager::getExchange('PreparedStatementTest.getTime');
     $stmt = $this->conn->prepareStatement($exch->getSql());
     $stmt->setInt(1, 1);
     $rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM);
     $rs->next();
     $this->assertEquals($now, $rs->getTime(1, null));
     $rs->close();
     $stmt->close();
 }
 public function testExecute()
 {
     $exch = DriverTestManager::getExchange('StatementTest.executeUpdate');
     $stmt = $this->conn->createStatement();
     $res = $stmt->execute($exch->getSql());
     $this->assertFalse($res, "Expected resulst of execute() to be FALSE because an update statement was executed (this is to match JDBC return values).");
     $this->assertEquals(1, $stmt->getUpdateCount());
     $exch = DriverTestManager::getExchange('StatementTest.executeQuery');
     $stmt = $this->conn->createStatement();
     $res = $stmt->execute($exch->getSql());
     $this->assertTrue($res, "Expected resulst of execute() to be TRUE because a select query was executed (this is to match JDBC return values).");
     $this->assertTrue($stmt->getResultSet() instanceof ResultSet, "Expected to be able to getResultSet() after call to execute() w/ SELECT query.");
     $stmt->close();
 }
 public function testRollback()
 {
     $exch = DriverTestManager::getExchange('RecordCount');
     $count_sql = $exch->getSql();
     $rs = $this->conn->executeQuery($count_sql, ResultSet::FETCHMODE_NUM);
     $rs->next();
     $total = $rs->getInt(1);
     // $this->assertEquals((int) $exch->getResult(), $total);
     $this->conn->setAutoCommit(false);
     // not sure exactly how to test this yet ...
     $exch = DriverTestManager::getExchange('ConnectionTest.setAutoCommit.DELTRAN1');
     $deleted1 = $this->conn->executeUpdate($exch->getSql());
     $exch = DriverTestManager::getExchange('ConnectionTest.setAutoCommit.DELTRAN2');
     $deleted2 = $this->conn->executeUpdate($exch->getSql());
     $this->conn->rollback();
     // compare the actual total w/ what we expect
     $rs = $this->conn->executeQuery($count_sql, ResultSet::FETCHMODE_NUM);
     $rs->next();
     $new_actual_total = $rs->getInt(1);
     $this->assertEquals($total, $new_actual_total, 0, "Failed to find correct (same) num of records in table after rollback().");
     $this->conn->setAutoCommit(true);
 }