This commit is contained in:
parent
bf749ae434
commit
7131ab9e95
@ -408,7 +408,7 @@ final class Doctrine
|
|||||||
*/
|
*/
|
||||||
public static function autoload($classname)
|
public static function autoload($classname)
|
||||||
{
|
{
|
||||||
if (class_exists($classname)) {
|
if (class_exists($classname, false)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (! self::$path) {
|
if (! self::$path) {
|
||||||
|
@ -488,7 +488,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function fetchAll($statement, array $params = array()) {
|
public function fetchAll($statement, array $params = array()) {
|
||||||
return $this->query($statement, $params)->fetchAll(PDO::FETCH_ASSOC);
|
return $this->execute($statement, $params)->fetchAll(PDO::FETCH_ASSOC);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* fetchOne
|
* fetchOne
|
||||||
@ -509,7 +509,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function fetchRow($statement, array $params = array()) {
|
public function fetchRow($statement, array $params = array()) {
|
||||||
return $this->query($statement, $params)->fetch(PDO::FETCH_ASSOC);
|
return $this->execute($statement, $params)->fetch(PDO::FETCH_ASSOC);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* fetchArray
|
* fetchArray
|
||||||
@ -519,7 +519,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function fetchArray($statement, array $params = array()) {
|
public function fetchArray($statement, array $params = array()) {
|
||||||
return $this->query($statement, $params)->fetch(PDO::FETCH_NUM);
|
return $this->execute($statement, $params)->fetch(PDO::FETCH_NUM);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* fetchColumn
|
* fetchColumn
|
||||||
@ -530,7 +530,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function fetchColumn($statement, array $params = array(), $colnum = 0) {
|
public function fetchColumn($statement, array $params = array(), $colnum = 0) {
|
||||||
return $this->query($statement, $params)->fetchAll(PDO::FETCH_COLUMN, $colnum);
|
return $this->execute($statement, $params)->fetchAll(PDO::FETCH_COLUMN, $colnum);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* fetchAssoc
|
* fetchAssoc
|
||||||
@ -540,7 +540,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function fetchAssoc($statement, array $params = array()) {
|
public function fetchAssoc($statement, array $params = array()) {
|
||||||
return $this->query($statement, $params)->fetchAll(PDO::FETCH_ASSOC);
|
return $this->execute($statement, $params)->fetchAll(PDO::FETCH_ASSOC);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* fetchBoth
|
* fetchBoth
|
||||||
@ -550,7 +550,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function fetchBoth($statement, array $params = array()) {
|
public function fetchBoth($statement, array $params = array()) {
|
||||||
return $this->query($statement, $params)->fetchAll(PDO::FETCH_BOTH);
|
return $this->execute($statement, $params)->fetchAll(PDO::FETCH_BOTH);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* query
|
* query
|
||||||
@ -650,7 +650,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
if ( ! empty($params)) {
|
if ( ! empty($params)) {
|
||||||
$stmt = $this->dbh->prepare($query);
|
$stmt = $this->dbh->prepare($query);
|
||||||
$stmt->execute($params);
|
$stmt->execute($params);
|
||||||
return $stmt;
|
return $stmt->rowCount();
|
||||||
} else {
|
} else {
|
||||||
return $this->dbh->exec($query);
|
return $this->dbh->exec($query);
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection
|
|||||||
*/
|
*/
|
||||||
public function quoteIdentifier($identifier, $checkOption = false)
|
public function quoteIdentifier($identifier, $checkOption = false)
|
||||||
{
|
{
|
||||||
if ($checkOption && ! $this->options['quote_identifier']) {
|
if ($checkOption && ! $this->getAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER)) {
|
||||||
return $identifier;
|
return $identifier;
|
||||||
}
|
}
|
||||||
return '[' . str_replace(']', ']]', $identifier) . ']';
|
return '[' . str_replace(']', ']]', $identifier) . ']';
|
||||||
@ -143,9 +143,8 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection
|
|||||||
*
|
*
|
||||||
* @param bool $native determines if the raw version string should be returned
|
* @param bool $native determines if the raw version string should be returned
|
||||||
* @return mixed array/string with version information or MDB2 error object
|
* @return mixed array/string with version information or MDB2 error object
|
||||||
* @access public
|
|
||||||
*/
|
*/
|
||||||
function getServerVersion($native = false)
|
public function getServerVersion($native = false)
|
||||||
{
|
{
|
||||||
if ($this->connected_server_info) {
|
if ($this->connected_server_info) {
|
||||||
$serverInfo = $this->connected_server_info;
|
$serverInfo = $this->connected_server_info;
|
||||||
|
@ -192,7 +192,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
|
|||||||
|
|
||||||
$this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->options['password']);
|
$this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->options['password']);
|
||||||
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
$this->dbh->setAttribute(PDO::ATTR_STATEMENT_CLASS, array("Doctrine_Db_Statement", array($this)));
|
$this->dbh->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Doctrine_Db_Statement', array($this)));
|
||||||
|
|
||||||
foreach($this->pendingAttributes as $attr => $value) {
|
foreach($this->pendingAttributes as $attr => $value) {
|
||||||
$this->dbh->setAttribute($attr, $value);
|
$this->dbh->setAttribute($attr, $value);
|
||||||
|
@ -84,7 +84,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
|
|||||||
* @param array $options An associative array of table options:
|
* @param array $options An associative array of table options:
|
||||||
* array(
|
* array(
|
||||||
* 'comment' => 'Foo',
|
* 'comment' => 'Foo',
|
||||||
* 'character_set' => 'utf8',
|
* 'charset' => 'utf8',
|
||||||
* 'collate' => 'utf8_unicode_ci',
|
* 'collate' => 'utf8_unicode_ci',
|
||||||
* 'collate' => 'utf8_unicode_ci',
|
* 'collate' => 'utf8_unicode_ci',
|
||||||
* 'type' => 'innodb',
|
* 'type' => 'innodb',
|
||||||
@ -94,18 +94,18 @@ class Doctrine_Export_Mysql extends Doctrine_Export
|
|||||||
*/
|
*/
|
||||||
public function createTable($name, array $fields, array $options = array()) {
|
public function createTable($name, array $fields, array $options = array()) {
|
||||||
if ( ! $name)
|
if ( ! $name)
|
||||||
throw new Doctrine_Export_Mysql_Exception('no valid table name specified');
|
throw new Doctrine_Export_Exception('no valid table name specified');
|
||||||
|
|
||||||
if (empty($fields)) {
|
if (empty($fields)) {
|
||||||
throw new Doctrine_Export_Mysql_Exception('no fields specified for table "'.$name.'"');
|
throw new Doctrine_Export_Exception('no fields specified for table "'.$name.'"');
|
||||||
}
|
}
|
||||||
$query_fields = $this->getFieldDeclarationList($fields);
|
$queryFields = $this->getFieldDeclarationList($fields);
|
||||||
|
|
||||||
if (isset($options['primary']) && ! empty($options['primary'])) {
|
if (isset($options['primary']) && ! empty($options['primary'])) {
|
||||||
$query_fields.= ', PRIMARY KEY(' . implode(', ', array_values($options['primary'])) . ')';
|
$queryFields .= ', PRIMARY KEY(' . implode(', ', array_values($options['primary'])) . ')';
|
||||||
}
|
}
|
||||||
$name = $this->conn->quoteIdentifier($name, true);
|
$name = $this->conn->quoteIdentifier($name, true);
|
||||||
$query = 'CREATE TABLE ' . $name . ' (' . $query_fields . ')';
|
$query = 'CREATE TABLE ' . $name . ' (' . $queryFields . ')';
|
||||||
|
|
||||||
$optionStrings = array();
|
$optionStrings = array();
|
||||||
|
|
||||||
@ -227,7 +227,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
|
|||||||
public function alterTable($name, array $changes, $check)
|
public function alterTable($name, array $changes, $check)
|
||||||
{
|
{
|
||||||
if ( ! $name)
|
if ( ! $name)
|
||||||
throw new Doctrine_Export_Mysql_Exception('no valid table name specified');
|
throw new Doctrine_Export_Exception('no valid table name specified');
|
||||||
|
|
||||||
foreach ($changes as $changeName => $change) {
|
foreach ($changes as $changeName => $change) {
|
||||||
switch ($changeName) {
|
switch ($changeName) {
|
||||||
@ -238,7 +238,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
|
|||||||
case 'name':
|
case 'name':
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Doctrine_Export_Mysql_Exception('change type "'.$changeName.'" not yet supported');
|
throw new Doctrine_Export_Exception('change type "'.$changeName.'" not yet supported');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,7 +324,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
|
|||||||
{
|
{
|
||||||
$query = 'CREATE TABLE ' . $sequenceName
|
$query = 'CREATE TABLE ' . $sequenceName
|
||||||
. ' (' . $seqcolName . ' INT NOT NULL AUTO_INCREMENT, PRIMARY KEY ('
|
. ' (' . $seqcolName . ' INT NOT NULL AUTO_INCREMENT, PRIMARY KEY ('
|
||||||
. $seqcol_name . '))'
|
. $seqcolName . '))'
|
||||||
. strlen($this->conn->default_table_type) ? ' TYPE = '
|
. strlen($this->conn->default_table_type) ? ' TYPE = '
|
||||||
. $this->conn->default_table_type : '';
|
. $this->conn->default_table_type : '';
|
||||||
|
|
||||||
@ -334,7 +334,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
$query = 'INSERT INTO ' . $sequenceName
|
$query = 'INSERT INTO ' . $sequenceName
|
||||||
. ' (' . $seqcol_name . ') VALUES (' . ($start - 1) . ')';
|
. ' (' . $seqcolName . ') VALUES (' . ($start - 1) . ')';
|
||||||
|
|
||||||
$res = $this->conn->exec($query);
|
$res = $this->conn->exec($query);
|
||||||
|
|
||||||
@ -342,10 +342,10 @@ class Doctrine_Export_Mysql extends Doctrine_Export
|
|||||||
try {
|
try {
|
||||||
$result = $this->conn->exec('DROP TABLE ' . $sequenceName);
|
$result = $this->conn->exec('DROP TABLE ' . $sequenceName);
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
throw new Doctrine_Export_Mysql_Exception('could not drop inconsistent sequence table');
|
throw new Doctrine_Export_Exception('could not drop inconsistent sequence table');
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Doctrine_Mysql_Export_Exception('could not create sequence table');
|
throw new Doctrine_Export_Exception('could not create sequence table');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get the stucture of a field into an array
|
* Get the stucture of a field into an array
|
||||||
|
@ -642,7 +642,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
|
|||||||
$b = array();
|
$b = array();
|
||||||
foreach ($map as $field => $value) {
|
foreach ($map as $field => $value) {
|
||||||
if ($index > 0) {
|
if ($index > 0) {
|
||||||
$b[] = '(' . $tableAlias . '.' . $field . ' = ' . $value . ' OR ' . $tableAlias . '.' . $field . ' IS NULL)';
|
$b[] = '(' . $tableAlias . '.' . $field . ' = ' . $value
|
||||||
|
. ' OR ' . $tableAlias . '.' . $field . ' IS NULL)';
|
||||||
} else {
|
} else {
|
||||||
$b[] = $tableAlias . '.' . $field . ' = ' . $value;
|
$b[] = $tableAlias . '.' . $field . ' = ' . $value;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
*/
|
*/
|
||||||
class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase {
|
class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase {
|
||||||
|
|
||||||
public function testUnknownModule() {
|
public function testUnknownModule() {
|
||||||
try {
|
try {
|
||||||
$this->connection->unknown;
|
$this->connection->unknown;
|
||||||
@ -48,7 +47,8 @@ class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase {
|
|||||||
$this->assertTrue($this->connection->export instanceof Doctrine_Export);
|
$this->assertTrue($this->connection->export instanceof Doctrine_Export);
|
||||||
}
|
}
|
||||||
public function testFetchAll() {
|
public function testFetchAll() {
|
||||||
$this->conn->exec('CREATE TABLE entity (id INTEGER, name TEXT)');
|
$this->conn->exec('DROP TABLE entity');
|
||||||
|
$this->conn->exec('CREATE TABLE entity (id INT, name TEXT)');
|
||||||
|
|
||||||
$this->conn->exec("INSERT INTO entity (id, name) VALUES (1, 'zYne')");
|
$this->conn->exec("INSERT INTO entity (id, name) VALUES (1, 'zYne')");
|
||||||
$this->conn->exec("INSERT INTO entity (id, name) VALUES (2, 'John')");
|
$this->conn->exec("INSERT INTO entity (id, name) VALUES (2, 'John')");
|
||||||
@ -127,172 +127,11 @@ class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
public function testFetchPairs() {
|
public function testFetchPairs() {
|
||||||
|
$this->conn->exec('DROP TABLE entity');
|
||||||
}
|
}
|
||||||
public function testFlush() {
|
|
||||||
$user = $this->connection->getTable('User')->find(4);
|
|
||||||
$this->assertTrue(is_numeric($user->Phonenumber[0]->entity_id));
|
|
||||||
|
|
||||||
$user = $this->connection->create('Email');
|
|
||||||
$user = $this->connection->create('User');
|
|
||||||
$record = $this->connection->create('Phonenumber');
|
|
||||||
|
|
||||||
$user->Email->address = 'example@drinkmore.info';
|
|
||||||
$this->assertTrue($user->email_id instanceof Email);
|
|
||||||
|
|
||||||
$user->name = 'Example user';
|
|
||||||
$user->Group[0]->name = 'Example group 1';
|
|
||||||
$user->Group[1]->name = 'Example group 2';
|
|
||||||
|
|
||||||
$user->Phonenumber[0]->phonenumber = '123 123';
|
|
||||||
|
|
||||||
$user->Phonenumber[1]->phonenumber = '321 2132';
|
|
||||||
$user->Phonenumber[2]->phonenumber = '123 123';
|
|
||||||
$user->Phonenumber[3]->phonenumber = '321 2132';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->assertTrue($user->Phonenumber[0]->entity_id instanceof User);
|
|
||||||
$this->assertTrue($user->Phonenumber[2]->entity_id instanceof User);
|
|
||||||
|
|
||||||
$this->connection->flush();
|
|
||||||
|
|
||||||
$this->assertTrue(is_numeric($user->Phonenumber[0]->entity_id));
|
|
||||||
|
|
||||||
$this->assertEqual(count($user->Group), 2);
|
|
||||||
$user2 = $user;
|
|
||||||
|
|
||||||
$user = $this->objTable->find($user->id);
|
|
||||||
|
|
||||||
$this->assertEqual($user->id, $user2->id);
|
|
||||||
|
|
||||||
$this->assertTrue(is_numeric($user->id));
|
|
||||||
$this->assertTrue(is_numeric($user->email_id));
|
|
||||||
|
|
||||||
$this->assertTrue(is_numeric($user->Phonenumber[0]->entity_id));
|
|
||||||
$this->assertTrue($user->Phonenumber->count(), 4);
|
|
||||||
$this->assertEqual($user->Group->count(), 2);
|
|
||||||
|
|
||||||
|
|
||||||
$user = $this->objTable->find(5);
|
|
||||||
|
|
||||||
$pf = $this->connection->getTable('Phonenumber');
|
|
||||||
|
|
||||||
$this->assertTrue($user->Phonenumber instanceof Doctrine_Collection);
|
|
||||||
$this->assertTrue($user->Phonenumber->count() == 3);
|
|
||||||
|
|
||||||
$coll = new Doctrine_Collection($pf);
|
|
||||||
|
|
||||||
$user->Phonenumber = $coll;
|
|
||||||
$this->assertTrue($user->Phonenumber->count() == 0);
|
|
||||||
|
|
||||||
$this->connection->flush();
|
|
||||||
unset($user);
|
|
||||||
$user = $this->objTable->find(5);
|
|
||||||
|
|
||||||
$this->assertEqual($user->Phonenumber->count(), 0);
|
|
||||||
|
|
||||||
// ADDING REFERENCES
|
|
||||||
|
|
||||||
$user->Phonenumber[0]->phonenumber = '123 123';
|
|
||||||
$this->assertTrue(is_numeric($user->Phonenumber[0]->entity_id));
|
|
||||||
|
|
||||||
$user->Phonenumber[1]->phonenumber = '123 123';
|
|
||||||
$this->connection->flush();
|
|
||||||
|
|
||||||
|
|
||||||
$this->assertEqual($user->Phonenumber->count(), 2);
|
|
||||||
|
|
||||||
unset($user);
|
|
||||||
$user = $this->objTable->find(5);
|
|
||||||
$this->assertEqual($user->Phonenumber->count(), 2);
|
|
||||||
|
|
||||||
$user->Phonenumber[3]->phonenumber = '123 123';
|
|
||||||
$this->connection->flush();
|
|
||||||
|
|
||||||
$this->assertEqual($user->Phonenumber->count(), 3);
|
|
||||||
unset($user);
|
|
||||||
$user = $this->objTable->find(5);
|
|
||||||
$this->assertEqual($user->Phonenumber->count(), 3);
|
|
||||||
|
|
||||||
// DELETING REFERENCES
|
|
||||||
|
|
||||||
$user->Phonenumber->delete();
|
|
||||||
|
|
||||||
$this->assertEqual($user->Phonenumber->count(), 0);
|
|
||||||
unset($user);
|
|
||||||
$user = $this->objTable->find(5);
|
|
||||||
$this->assertEqual($user->Phonenumber->count(), 0);
|
|
||||||
|
|
||||||
// ADDING REFERENCES WITH STRING KEYS
|
|
||||||
|
|
||||||
$user->Phonenumber['home']->phonenumber = '123 123';
|
|
||||||
$user->Phonenumber['work']->phonenumber = '444 444';
|
|
||||||
|
|
||||||
$this->assertEqual($user->Phonenumber->count(), 2);
|
|
||||||
$this->connection->flush();
|
|
||||||
|
|
||||||
$this->assertEqual($user->Phonenumber->count(), 2);
|
|
||||||
unset($user);
|
|
||||||
$user = $this->objTable->find(5);
|
|
||||||
$this->assertEqual($user->Phonenumber->count(), 2);
|
|
||||||
|
|
||||||
// REPLACING ONE-TO-MANY REFERENCE
|
|
||||||
|
|
||||||
unset($coll);
|
|
||||||
$coll = new Doctrine_Collection($pf);
|
|
||||||
$coll[0]->phonenumber = '123 123';
|
|
||||||
$coll['home']->phonenumber = '444 444';
|
|
||||||
$coll['work']->phonenumber = '444 444';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$user->Phonenumber = $coll;
|
|
||||||
$this->connection->flush();
|
|
||||||
$this->assertEqual($user->Phonenumber->count(), 3);
|
|
||||||
$user = $this->objTable->find(5);
|
|
||||||
$this->assertEqual($user->Phonenumber->count(), 3);
|
|
||||||
|
|
||||||
|
|
||||||
// ONE-TO-ONE REFERENCES
|
|
||||||
|
|
||||||
$user->Email->address = 'drinker@drinkmore.info';
|
|
||||||
$this->assertTrue($user->Email instanceof Email);
|
|
||||||
$this->connection->flush();
|
|
||||||
$this->assertTrue($user->Email instanceof Email);
|
|
||||||
$user = $this->objTable->find(5);
|
|
||||||
$this->assertEqual($user->Email->address, 'drinker@drinkmore.info');
|
|
||||||
$id = $user->Email->id;
|
|
||||||
|
|
||||||
// REPLACING ONE-TO-ONE REFERENCES
|
|
||||||
|
|
||||||
$email = $this->connection->create('Email');
|
|
||||||
$email->address = 'absolutist@nottodrink.com';
|
|
||||||
$user->Email = $email;
|
|
||||||
|
|
||||||
$this->assertTrue($user->Email instanceof Email);
|
|
||||||
$this->assertEqual($user->Email->address, 'absolutist@nottodrink.com');
|
|
||||||
$this->connection->flush();
|
|
||||||
unset($user);
|
|
||||||
|
|
||||||
$user = $this->objTable->find(5);
|
|
||||||
$this->assertTrue($user->Email instanceof Email);
|
|
||||||
$this->assertEqual($user->Email->address, 'absolutist@nottodrink.com');
|
|
||||||
|
|
||||||
$emails = $this->connection->query("FROM Email WHERE Email.id = $id");
|
|
||||||
//$this->assertEqual(count($emails),0);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetManager() {
|
public function testGetManager() {
|
||||||
$this->assertEqual($this->connection->getManager(),$this->manager);
|
$this->assertEqual($this->connection->getManager(),$this->manager);
|
||||||
}
|
}
|
||||||
public function testQuery() {
|
|
||||||
$this->assertTrue($this->connection->query('FROM User') instanceof Doctrine_Collection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDelete() {
|
public function testDelete() {
|
||||||
$user = $this->connection->create('User');
|
$user = $this->connection->create('User');
|
||||||
$this->connection->delete($user);
|
$this->connection->delete($user);
|
||||||
@ -333,27 +172,6 @@ class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase {
|
|||||||
public function testGetTables() {
|
public function testGetTables() {
|
||||||
$this->assertTrue(is_array($this->connection->getTables()));
|
$this->assertTrue(is_array($this->connection->getTables()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTransactions() {
|
|
||||||
|
|
||||||
$this->connection->beginTransaction();
|
|
||||||
$this->assertEqual($this->connection->transaction->getState(),Doctrine_Transaction::STATE_ACTIVE);
|
|
||||||
$this->connection->commit();
|
|
||||||
$this->assertEqual($this->connection->transaction->getState(),Doctrine_Transaction::STATE_SLEEP);
|
|
||||||
|
|
||||||
$this->connection->beginTransaction();
|
|
||||||
|
|
||||||
$user = $this->objTable->find(6);
|
|
||||||
|
|
||||||
$user->name = 'Jack Daniels';
|
|
||||||
$this->connection->flush();
|
|
||||||
$this->connection->commit();
|
|
||||||
|
|
||||||
$user = $this->objTable->find(6);
|
|
||||||
$this->assertEqual($user->name, 'Jack Daniels');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRollback() {
|
public function testRollback() {
|
||||||
$this->connection->beginTransaction();
|
$this->connection->beginTransaction();
|
||||||
$this->assertEqual($this->connection->transaction->getTransactionLevel(),1);
|
$this->assertEqual($this->connection->transaction->getTransactionLevel(),1);
|
||||||
|
@ -6,23 +6,34 @@ class AdapterMock implements Doctrine_Adapter_Interface {
|
|||||||
|
|
||||||
private $exception = array();
|
private $exception = array();
|
||||||
|
|
||||||
public function __construct($name) {
|
private $lastInsertIdFail = false;
|
||||||
|
|
||||||
|
public function __construct($name)
|
||||||
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
}
|
}
|
||||||
public function getName() {
|
public function getName()
|
||||||
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
public function pop() {
|
public function pop()
|
||||||
|
{
|
||||||
return array_pop($this->queries);
|
return array_pop($this->queries);
|
||||||
}
|
}
|
||||||
public function forceException($name, $message = '', $code = 0) {
|
public function forceException($name, $message = '', $code = 0)
|
||||||
|
{
|
||||||
$this->exception = array($name, $message, $code);
|
$this->exception = array($name, $message, $code);
|
||||||
}
|
}
|
||||||
public function prepare($prepareString){
|
public function prepare($query)
|
||||||
return new AdapterStatementMock;
|
{
|
||||||
|
return new AdapterStatementMock($this, $query);
|
||||||
}
|
}
|
||||||
public function query($queryString) {
|
public function addQuery($query)
|
||||||
$this->queries[] = $queryString;
|
{
|
||||||
|
$this->queries[] = $query;
|
||||||
|
}
|
||||||
|
public function query($query) {
|
||||||
|
$this->queries[] = $query;
|
||||||
|
|
||||||
$e = $this->exception;
|
$e = $this->exception;
|
||||||
|
|
||||||
@ -34,7 +45,7 @@ class AdapterMock implements Doctrine_Adapter_Interface {
|
|||||||
throw new $name($e[1], $e[2]);
|
throw new $name($e[1], $e[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AdapterStatementMock;
|
return new AdapterStatementMock($this, $query);
|
||||||
}
|
}
|
||||||
public function getAll() {
|
public function getAll() {
|
||||||
return $this->queries;
|
return $this->queries;
|
||||||
@ -57,18 +68,28 @@ class AdapterMock implements Doctrine_Adapter_Interface {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
public function forceLastInsertIdFail() {
|
||||||
|
$this->lastInsertIdFail = true;
|
||||||
|
}
|
||||||
public function lastInsertId()
|
public function lastInsertId()
|
||||||
{
|
{
|
||||||
$this->queries[] = 'LAST_INSERT_ID()';
|
$this->queries[] = 'LAST_INSERT_ID()';
|
||||||
|
if ($this->lastInsertIdFail) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public function beginTransaction(){
|
public function beginTransaction(){
|
||||||
$this->queries[] = 'BEGIN TRANSACTION';
|
$this->queries[] = 'BEGIN TRANSACTION';
|
||||||
}
|
}
|
||||||
public function commit(){
|
public function commit(){
|
||||||
$this->queries[] = 'COMMIT';
|
$this->queries[] = 'COMMIT';
|
||||||
}
|
}
|
||||||
public function rollBack(){ }
|
public function rollBack()
|
||||||
|
{
|
||||||
|
$this->queries[] = 'ROLLBACK';
|
||||||
|
}
|
||||||
public function errorCode(){ }
|
public function errorCode(){ }
|
||||||
public function errorInfo(){ }
|
public function errorInfo(){ }
|
||||||
public function getAttribute($attribute) {
|
public function getAttribute($attribute) {
|
||||||
@ -80,6 +101,15 @@ class AdapterMock implements Doctrine_Adapter_Interface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
class AdapterStatementMock {
|
class AdapterStatementMock {
|
||||||
|
|
||||||
|
private $mock;
|
||||||
|
|
||||||
|
private $query;
|
||||||
|
|
||||||
|
public function __construct(AdapterMock $mock, $query) {
|
||||||
|
$this->mock = $mock;
|
||||||
|
$this->query = $query;
|
||||||
|
}
|
||||||
public function fetch($fetchMode) {
|
public function fetch($fetchMode) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
@ -87,6 +117,7 @@ class AdapterStatementMock {
|
|||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
public function execute() {
|
public function execute() {
|
||||||
|
$this->mock->addQuery($this->query);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public function fetchColumn($colnum) {
|
public function fetchColumn($colnum) {
|
||||||
|
@ -40,29 +40,29 @@ class Doctrine_Sequence_TestCase extends Doctrine_UnitTestCase
|
|||||||
}
|
}
|
||||||
public function testSequencesAreSupportedForRecords()
|
public function testSequencesAreSupportedForRecords()
|
||||||
{
|
{
|
||||||
$this->profiler = new Doctrine_Db_Profiler();
|
$this->adapter->forceLastInsertIdFail();
|
||||||
|
|
||||||
$this->dbh->setListener($this->profiler);
|
|
||||||
|
|
||||||
$r = new CustomSequenceRecord;
|
$r = new CustomSequenceRecord;
|
||||||
$r->name = 'custom seq';
|
$r->name = 'custom seq';
|
||||||
$r->save();
|
$r->save();
|
||||||
|
|
||||||
|
/**
|
||||||
// the last profiled event is transaction commit
|
// the last profiled event is transaction commit
|
||||||
$this->assertEqual($this->profiler->pop()->getType(), Doctrine_Db_Event::COMMIT);
|
$this->assertEqual($this->adapter->pop(), 'COMMIT');
|
||||||
// query execution
|
// query execution
|
||||||
$this->assertEqual($this->profiler->pop()->getQuery(), 'INSERT INTO custom_sequence_record (name, id) VALUES (?, ?)');
|
|
||||||
|
$this->assertEqual($this->adapter->pop(), 'INSERT INTO custom_sequence_record (name, id) VALUES (?, ?)');
|
||||||
// query prepare
|
// query prepare
|
||||||
$this->assertEqual($this->profiler->pop()->getQuery(), 'INSERT INTO custom_sequence_record (name, id) VALUES (?, ?)');
|
$this->assertEqual($this->adapter->pop(), 'INSERT INTO custom_sequence_record (name, id) VALUES (?, ?)');
|
||||||
|
|
||||||
// sequence generation (first fails)
|
// sequence generation (first fails)
|
||||||
$this->assertEqual($this->profiler->pop()->getQuery(), 'INSERT INTO custom_seq_seq (id) VALUES (1)');
|
$this->assertEqual($this->adapter->pop(), 'INSERT INTO custom_seq_seq (id) VALUES (1)');
|
||||||
$this->assertEqual($this->profiler->pop()->getQuery(), 'CREATE TABLE custom_seq_seq (id INTEGER PRIMARY KEY DEFAULT 0 NOT NULL)');
|
$this->assertEqual($this->adapter->pop(), 'CREATE TABLE custom_seq_seq (id INTEGER PRIMARY KEY DEFAULT 0 NOT NULL)');
|
||||||
$this->assertEqual($this->profiler->pop()->getQuery(), 'INSERT INTO custom_seq_seq (id) VALUES (NULL)');
|
$this->assertEqual($this->adapter->pop(), 'INSERT INTO custom_seq_seq (id) VALUES (NULL)');
|
||||||
|
|
||||||
// transaction begin
|
// transaction begin
|
||||||
$this->assertEqual($this->profiler->pop()->getType(), Doctrine_Db_Event::BEGIN);
|
$this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION');
|
||||||
$this->assertEqual($this->profiler->pop()->getQuery(), 'CREATE TABLE custom_sequence_record (id INTEGER, name VARCHAR(2147483647), PRIMARY KEY(id))');
|
$this->assertEqual($this->adapter->pop(), 'CREATE TABLE custom_sequence_record (id INTEGER, name VARCHAR(2147483647), PRIMARY KEY(id))');
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class CustomSequenceRecord extends Doctrine_Record {
|
class CustomSequenceRecord extends Doctrine_Record {
|
||||||
|
@ -63,6 +63,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
|
|||||||
case 'Expression':
|
case 'Expression':
|
||||||
case 'Transaction':
|
case 'Transaction':
|
||||||
case 'DataDict':
|
case 'DataDict':
|
||||||
|
case 'Sequence':
|
||||||
$this->driverName = 'Sqlite';
|
$this->driverName = 'Sqlite';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -83,7 +84,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->connection = $this->manager->getConnection($this->driverName);
|
$this->conn = $this->connection = $this->manager->getConnection($this->driverName);
|
||||||
$this->connection->evictTables();
|
$this->connection->evictTables();
|
||||||
$this->dbh = $this->adapter = $this->connection->getDbh();
|
$this->dbh = $this->adapter = $this->connection->getDbh();
|
||||||
$this->listener = $this->manager->getAttribute(Doctrine::ATTR_LISTENER);
|
$this->listener = $this->manager->getAttribute(Doctrine::ATTR_LISTENER);
|
||||||
@ -91,12 +92,12 @@ class Doctrine_UnitTestCase extends UnitTestCase {
|
|||||||
$this->manager->setAttribute(Doctrine::ATTR_LISTENER, $this->listener);
|
$this->manager->setAttribute(Doctrine::ATTR_LISTENER, $this->listener);
|
||||||
} catch(Doctrine_Manager_Exception $e) {
|
} catch(Doctrine_Manager_Exception $e) {
|
||||||
if($this->driverName == 'main') {
|
if($this->driverName == 'main') {
|
||||||
$this->dbh = Doctrine_Db::getConnection("sqlite::memory:");
|
$this->dbh = Doctrine_Db::getConnection('sqlite::memory:');
|
||||||
} else {
|
} else {
|
||||||
$this->dbh = $this->adapter = new AdapterMock($this->driverName);
|
$this->dbh = $this->adapter = new AdapterMock($this->driverName);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->connection = $this->manager->openConnection($this->dbh, $this->driverName);
|
$this->conn = $this->connection = $this->manager->openConnection($this->dbh, $this->driverName);
|
||||||
|
|
||||||
if($this->driverName !== 'main') {
|
if($this->driverName !== 'main') {
|
||||||
$exc = 'Doctrine_Connection_' . ucwords($this->driverName) . '_Exception';
|
$exc = 'Doctrine_Connection_' . ucwords($this->driverName) . '_Exception';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user