저자: Mike Lively (m@digitalsandwich.com)
상속: implements PHPUnit_Extensions_Database_DB_IMetaData
예제 #1
0
 /**
  * Creates a new database connection
  *
  * @param PDO $connection
  * @param string $schema - The name of the database schema you will be testing against.
  */
 public function __construct(PDO $connection, $schema)
 {
     $this->connection = $connection;
     $this->metaData = PHPUnit_Extensions_Database_DB_MetaData::createMetaData($connection, $schema);
     $this->schema = $schema;
     $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 }
예제 #2
0
파일: MetaData.php 프로젝트: cwcw/cms
 /**
  * Creates a meta data object based on the driver of given connection and
  * $schema name.
  *
  * @param PDO|resource $connection
  * @param string $schema
  * @return PHPUnit_Extensions_Database_DB_IMetaData
  */
 public static function createMetaData($connection, $schema)
 {
     // for PDO use PHPUnit_Extensions_Database_DB_IMetaData
     if ($connection instanceof PDO) {
         $driverName = $connection->getAttribute(PDO::ATTR_DRIVER_NAME);
         // register overloaded classes maps for pdo
         if (isset(self::$metaDataClassMap[$driverName])) {
             $className = self::$metaDataClassMap[$driverName];
             PHPUnit_Extensions_Database_DB_MetaData::registerClassWithDriver($className, $driverName);
         }
         return PHPUnit_Extensions_Database_DB_MetaData::createMetaData($connection, $connection);
     }
     $driverName = 'oracle';
     if (isset(self::$metaDataClassMap[$driverName])) {
         $className = self::$metaDataClassMap[$driverName];
         if ($className instanceof ReflectionClass) {
             return $className->newInstance($connection, $schema);
         } else {
             return self::registerClassWithDriver($className, $driverName)->newInstance($connection, $schema);
         }
     } else {
         throw new Exception("Could not find a meta data driver for {$driverName} driver.");
     }
 }