/** * Set up the test database table. * * @param PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection $connection */ protected function setUpTable($connection) { $pdo = $connection->getConnection(); $sql = 'CREATE TABLE IF NOT EXISTS simple_table ( id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50) NOT NULL, email VARCHAR(50) NOT NULL, address VARCHAR(100) )'; $pdo->exec($sql); $sql = 'CREATE TABLE IF NOT EXISTS books_array ( id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY, book_id VARCHAR(50) NOT NULL, info TEXT NOT NULL )'; $pdo->exec($sql); $sql = 'CREATE TABLE IF NOT EXISTS books_columns ( id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY, author VARCHAR(100) NOT NULL, title VARCHAR(100) NOT NULL, genre VARCHAR(100) NOT NULL, price VARCHAR(50) NOT NULL, publish_date VARCHAR(50) NOT NULL, description TEXT NOT NULL )'; $pdo->exec($sql); }
public function testRowCountForTableWithTwoRowsReturnsTwo() { $this->db->exec('INSERT INTO test (field1) VALUES (\'foobar\')'); $this->db->exec('INSERT INTO test (field1) VALUES (\'foobarbaz\')'); $conn = new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection($this->db); $this->assertEquals(2, $conn->getRowCount('test')); }
/** * Creates a DB Data Set from a data set spec. * * @param string $dataSetSpec * @return PHPUnit_Extensions_Database_DataSet_IDataSet */ public function getDataSet($dataSetSpec) { list($dbLabel, $schema, $tables) = explode(':', $dataSetSpec, 3); $databaseInfo = $this->databases[$dbLabel]; $pdoRflc = new ReflectionClass('PDO'); $pdo = $pdoRflc->newInstanceArgs(explode('|', $databaseInfo)); $dbConnection = new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection($pdo, $schema); return !empty($tables) ? $dbConnection->createDataSet(explode(',', $tables)) : $dbConnection->createDataSet(); }
/** * Creates a Default Data Set with a query table from a data set spec. * * @param string $dataSetSpec * @return PHPUnit_Extensions_Database_DataSet_DefaultDataSet */ public function getDataSet($dataSetSpec) { list($dbLabel, $schema, $table, $sql) = explode(':', $dataSetSpec, 4); $databaseInfo = $this->databases[$dbLabel]; $pdoRflc = new ReflectionClass('PDO'); $pdo = $pdoRflc->newInstanceArgs(explode('|', $databaseInfo)); $dbConnection = new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection($pdo, $schema); $table = $dbConnection->createQueryTable($table, $sql); return new PHPUnit_Extensions_Database_DataSet_DefaultDataSet([$table]); }
protected 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']); $this->conn->getConnection()->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT); } return $this->conn; }
/** * Returns a list of table names for the database * * @return Array */ public function getTableNames() { return $this->databaseConnection->getMetaData()->getTableNames(); }