Commit 7131ab9e authored by zYne's avatar zYne

--no commit message

--no commit message
parent bf749ae4
......@@ -408,13 +408,13 @@ final class Doctrine
*/
public static function autoload($classname)
{
if (class_exists($classname)) {
if (class_exists($classname, false)) {
return false;
}
if (! self::$path) {
self::$path = dirname(__FILE__);
}
$class = self::$path.DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR,$classname) . '.php';
$class = self::$path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR,$classname) . '.php';
if ( ! file_exists($class)) {
return false;
......
......@@ -488,7 +488,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return 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
......@@ -509,7 +509,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return 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
......@@ -519,7 +519,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return 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
......@@ -530,7 +530,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return array
*/
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
......@@ -540,7 +540,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return 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
......@@ -550,7 +550,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return 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
......@@ -650,7 +650,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
if ( ! empty($params)) {
$stmt = $this->dbh->prepare($query);
$stmt->execute($params);
return $stmt;
return $stmt->rowCount();
} else {
return $this->dbh->exec($query);
}
......
......@@ -79,7 +79,7 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection
*/
public function quoteIdentifier($identifier, $checkOption = false)
{
if ($checkOption && ! $this->options['quote_identifier']) {
if ($checkOption && ! $this->getAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER)) {
return $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
* @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) {
$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->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) {
$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:
* array(
* 'comment' => 'Foo',
* 'character_set' => 'utf8',
* 'charset' => 'utf8',
* 'collate' => 'utf8_unicode_ci',
* 'collate' => 'utf8_unicode_ci',
* 'type' => 'innodb',
......@@ -94,18 +94,18 @@ class Doctrine_Export_Mysql extends Doctrine_Export
*/
public function createTable($name, array $fields, array $options = array()) {
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)) {
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'])) {
$query_fields.= ', PRIMARY KEY(' . implode(', ', array_values($options['primary'])) . ')';
$queryFields .= ', PRIMARY KEY(' . implode(', ', array_values($options['primary'])) . ')';
}
$name = $this->conn->quoteIdentifier($name, true);
$query = 'CREATE TABLE ' . $name . ' (' . $query_fields . ')';
$query = 'CREATE TABLE ' . $name . ' (' . $queryFields . ')';
$optionStrings = array();
......@@ -227,7 +227,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
public function alterTable($name, array $changes, $check)
{
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) {
switch ($changeName) {
......@@ -238,7 +238,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
case 'name':
break;
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
. ' (' . $seqcolName . ' INT NOT NULL AUTO_INCREMENT, PRIMARY KEY ('
. $seqcol_name . '))'
. $seqcolName . '))'
. strlen($this->conn->default_table_type) ? ' TYPE = '
. $this->conn->default_table_type : '';
......@@ -334,7 +334,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
return true;
$query = 'INSERT INTO ' . $sequenceName
. ' (' . $seqcol_name . ') VALUES (' . ($start - 1) . ')';
. ' (' . $seqcolName . ') VALUES (' . ($start - 1) . ')';
$res = $this->conn->exec($query);
......@@ -342,10 +342,10 @@ class Doctrine_Export_Mysql extends Doctrine_Export
try {
$result = $this->conn->exec('DROP TABLE ' . $sequenceName);
} 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
......
......@@ -642,7 +642,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
$b = array();
foreach ($map as $field => $value) {
if ($index > 0) {
$b[] = '(' . $tableAlias . '.' . $field . ' = ' . $value . ' OR ' . $tableAlias . '.' . $field . ' IS NULL)';
$b[] = '(' . $tableAlias . '.' . $field . ' = ' . $value
. ' OR ' . $tableAlias . '.' . $field . ' IS NULL)';
} else {
$b[] = $tableAlias . '.' . $field . ' = ' . $value;
}
......
......@@ -31,7 +31,6 @@
* @version $Revision$
*/
class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase {
public function testUnknownModule() {
try {
$this->connection->unknown;
......@@ -48,7 +47,8 @@ class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase {
$this->assertTrue($this->connection->export instanceof Doctrine_Export);
}
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 (2, 'John')");
......@@ -127,172 +127,11 @@ class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase {
));
}
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() {
$this->assertEqual($this->connection->getManager(),$this->manager);
}
public function testQuery() {
$this->assertTrue($this->connection->query('FROM User') instanceof Doctrine_Collection);
}
public function testDelete() {
$user = $this->connection->create('User');
$this->connection->delete($user);
......@@ -333,27 +172,6 @@ class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase {
public function testGetTables() {
$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() {
$this->connection->beginTransaction();
$this->assertEqual($this->connection->transaction->getTransactionLevel(),1);
......
......@@ -6,23 +6,34 @@ class AdapterMock implements Doctrine_Adapter_Interface {
private $exception = array();
public function __construct($name) {
private $lastInsertIdFail = false;
public function __construct($name)
{
$this->name = $name;
}
public function getName() {
public function getName()
{
return $this->name;
}
public function pop() {
public function pop()
{
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);
}
public function prepare($prepareString){
return new AdapterStatementMock;
public function prepare($query)
{
return new AdapterStatementMock($this, $query);
}
public function addQuery($query)
{
$this->queries[] = $query;
}
public function query($queryString) {
$this->queries[] = $queryString;
public function query($query) {
$this->queries[] = $query;
$e = $this->exception;
......@@ -34,7 +45,7 @@ class AdapterMock implements Doctrine_Adapter_Interface {
throw new $name($e[1], $e[2]);
}
return new AdapterStatementMock;
return new AdapterStatementMock($this, $query);
}
public function getAll() {
return $this->queries;
......@@ -57,18 +68,28 @@ class AdapterMock implements Doctrine_Adapter_Interface {
return 0;
}
public function forceLastInsertIdFail() {
$this->lastInsertIdFail = true;
}
public function lastInsertId()
{
$this->queries[] = 'LAST_INSERT_ID()';
if ($this->lastInsertIdFail) {
return null;
} else {
return 1;
}
}
public function beginTransaction(){
$this->queries[] = 'BEGIN TRANSACTION';
}
public function commit(){
$this->queries[] = 'COMMIT';
}
public function rollBack(){ }
public function rollBack()
{
$this->queries[] = 'ROLLBACK';
}
public function errorCode(){ }
public function errorInfo(){ }
public function getAttribute($attribute) {
......@@ -80,6 +101,15 @@ class AdapterMock implements Doctrine_Adapter_Interface {
}
}
class AdapterStatementMock {
private $mock;
private $query;
public function __construct(AdapterMock $mock, $query) {
$this->mock = $mock;
$this->query = $query;
}
public function fetch($fetchMode) {
return array();
}
......@@ -87,6 +117,7 @@ class AdapterStatementMock {
return array();
}
public function execute() {
$this->mock->addQuery($this->query);
return true;
}
public function fetchColumn($colnum) {
......
......@@ -40,29 +40,29 @@ class Doctrine_Sequence_TestCase extends Doctrine_UnitTestCase
}
public function testSequencesAreSupportedForRecords()
{
$this->profiler = new Doctrine_Db_Profiler();
$this->dbh->setListener($this->profiler);
$this->adapter->forceLastInsertIdFail();
$r = new CustomSequenceRecord;
$r->name = 'custom seq';
$r->save();
/**
// 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
$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
$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)
$this->assertEqual($this->profiler->pop()->getQuery(), '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->profiler->pop()->getQuery(), 'INSERT INTO custom_seq_seq (id) VALUES (NULL)');
$this->assertEqual($this->adapter->pop(), 'INSERT INTO custom_seq_seq (id) VALUES (1)');
$this->assertEqual($this->adapter->pop(), 'CREATE TABLE custom_seq_seq (id INTEGER PRIMARY KEY DEFAULT 0 NOT NULL)');
$this->assertEqual($this->adapter->pop(), 'INSERT INTO custom_seq_seq (id) VALUES (NULL)');
// transaction begin
$this->assertEqual($this->profiler->pop()->getType(), Doctrine_Db_Event::BEGIN);
$this->assertEqual($this->profiler->pop()->getQuery(), 'CREATE TABLE custom_sequence_record (id INTEGER, name VARCHAR(2147483647), PRIMARY KEY(id))');
$this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION');
$this->assertEqual($this->adapter->pop(), 'CREATE TABLE custom_sequence_record (id INTEGER, name VARCHAR(2147483647), PRIMARY KEY(id))');
*/
}
}
class CustomSequenceRecord extends Doctrine_Record {
......
......@@ -63,6 +63,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
case 'Expression':
case 'Transaction':
case 'DataDict':
case 'Sequence':
$this->driverName = 'Sqlite';
break;
}
......@@ -83,7 +84,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
}
try {
$this->connection = $this->manager->getConnection($this->driverName);
$this->conn = $this->connection = $this->manager->getConnection($this->driverName);
$this->connection->evictTables();
$this->dbh = $this->adapter = $this->connection->getDbh();
$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);
} catch(Doctrine_Manager_Exception $e) {
if($this->driverName == 'main') {
$this->dbh = Doctrine_Db::getConnection("sqlite::memory:");
$this->dbh = Doctrine_Db::getConnection('sqlite::memory:');
} else {
$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') {
$exc = 'Doctrine_Connection_' . ucwords($this->driverName) . '_Exception';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment