Commit 7b52c80c authored by zYne's avatar zYne

Refactored Doctrine_Connection: separated into two different classes...

Refactored Doctrine_Connection: separated into two different classes Doctrine_Connection and Doctrine_Transaction
parent 8edafac8
......@@ -511,7 +511,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if(isset($this->keyColumn)) {
$value = $record->get($this->keyColumn);
if($value === null)
throw new Doctrine_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null.");
throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null.");
$this->data[$value] = $record;
} else
......@@ -544,7 +544,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if(isset($this->keyColumn)) {
$value = $record->get($this->keyColumn);
if($value === null)
throw new Doctrine_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null.");
throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null.");
$this->data[$value] = $record;
} else
......@@ -579,7 +579,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$value = $record->get($this->keyColumn);
if($value === null)
throw new Doctrine_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null.");
throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null.");
$this->data[$value] = $record;
unset($this->data[$k]);
......@@ -591,6 +591,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* loadRelated
*
* @param mixed $name
* @return boolean
*/
public function loadRelated($name = null) {
$query = new Doctrine_Query($this->table->getConnection());
......
......@@ -87,12 +87,12 @@ abstract class Doctrine_Configurable {
break;
case Doctrine::ATTR_LOCKMODE:
if($this instanceof Doctrine_Connection) {
if($this->getState() != Doctrine_Connection::STATE_OPEN)
if($this->getTransaction()->getState() != Doctrine_Transaction::STATE_OPEN)
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
} elseif($this instanceof Doctrine_Manager) {
foreach($this as $connection) {
if($connection->getState() != Doctrine_Connection::STATE_OPEN)
if($connection->getTransaction()->getState() != Doctrine_Transaction::STATE_OPEN)
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
}
} else {
......
This diff is collapsed.
......@@ -73,16 +73,16 @@ class Doctrine_Lib {
*/
public static function getConnectionStateAsString($state) {
switch($state):
case Doctrine_Connection::STATE_OPEN:
case Doctrine_Transaction::STATE_OPEN:
return "open";
break;
case Doctrine_Connection::STATE_CLOSED:
case Doctrine_Transaction::STATE_CLOSED:
return "closed";
break;
case Doctrine_Connection::STATE_BUSY:
case Doctrine_Transaction::STATE_BUSY:
return "busy";
break;
case Doctrine_Connection::STATE_ACTIVE:
case Doctrine_Transaction::STATE_ACTIVE:
return "active";
break;
endswitch;
......
......@@ -1112,6 +1112,17 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public function hasReference($name) {
return isset($this->references[$name]);
}
/**
* obtainReference
*
* @param string $name
*/
public function obtainReference($name) {
if(isset($this->references[$name]))
return $this->references[$name];
throw new Doctrine_Record_Exception("Unknown reference $name");
}
/**
* initalizes a one-to-one relation
*
......
......@@ -313,8 +313,8 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase {
$this->assertTrue($this->connection->getIterator() instanceof ArrayIterator);
}
public function testGetState() {
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_OPEN);
$this->assertEqual(Doctrine_Lib::getConnectionStateAsString($this->connection->getState()), "open");
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_OPEN);
$this->assertEqual(Doctrine_Lib::getConnectionStateAsString($this->connection->getTransaction()->getState()), "open");
}
public function testGetTables() {
$this->assertTrue(is_array($this->connection->getTables()));
......@@ -323,9 +323,9 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase {
public function testTransactions() {
$this->connection->beginTransaction();
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_ACTIVE);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_ACTIVE);
$this->connection->commit();
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_OPEN);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_OPEN);
$this->connection->beginTransaction();
......@@ -343,24 +343,24 @@ class Doctrine_ConnectionTestCase extends Doctrine_UnitTestCase {
public function testRollback() {
$this->connection->beginTransaction();
$this->assertEqual($this->connection->getTransactionLevel(),1);
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_ACTIVE);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_ACTIVE);
$this->connection->rollback();
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_OPEN);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_OPEN);
$this->assertEqual($this->connection->getTransactionLevel(),0);
}
public function testNestedTransactions() {
$this->assertEqual($this->connection->getTransactionLevel(),0);
$this->connection->beginTransaction();
$this->assertEqual($this->connection->getTransactionLevel(),1);
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_ACTIVE);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_ACTIVE);
$this->connection->beginTransaction();
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_BUSY);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_BUSY);
$this->assertEqual($this->connection->getTransactionLevel(),2);
$this->connection->commit();
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_ACTIVE);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_ACTIVE);
$this->assertEqual($this->connection->getTransactionLevel(),1);
$this->connection->commit();
$this->assertEqual($this->connection->getState(),Doctrine_Connection::STATE_OPEN);
$this->assertEqual($this->connection->getTransaction()->getState(),Doctrine_Transaction::STATE_OPEN);
$this->assertEqual($this->connection->getTransactionLevel(),0);
}
}
......
......@@ -30,7 +30,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->connection->clear();
}
/**
public function testBracktExplode() {
$str = "item OR item || item";
$parts = Doctrine_Query::bracketExplode($str, array(' \|\| ', ' OR '), "(", ")");
......@@ -1274,6 +1274,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
//$this->assertTrue(isset($values['max']));
}
*/
}
?>
......@@ -4,6 +4,7 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
$this->tables[] = "ValidatorTest";
parent::prepareTables();
}
public function testIsValidType() {
$var = "123";
$this->assertTrue(Doctrine_Validator::isValidType($var,"string"));
......@@ -144,6 +145,7 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
}
public function testSave() {
$this->manager->setAttribute(Doctrine::ATTR_VLD, true);
$user = $this->connection->getTable("User")->find(4);
......
......@@ -32,7 +32,12 @@ require_once("ImportTestCase.php");
error_reporting(E_ALL);
$test = new GroupTest("Doctrine Framework Unit Tests");
/**
$test->addTestCase(new Doctrine_ConnectionTestCase());
$test->addTestCase(new Doctrine_RecordTestCase());
$test->addTestCase(new Doctrine_AccessTestCase());
......@@ -41,14 +46,14 @@ $test->addTestCase(new Doctrine_EventListenerTestCase());
$test->addTestCase(new Doctrine_TableTestCase());
$test->addTestCase(new Doctrine_ConnectionTestCase());
$test->addTestCase(new Doctrine_ManagerTestCase());
$test->addTestCase(new Doctrine_BatchIteratorTestCase());
$test->addTestCase(new Doctrine_ConfigurableTestCase());
$test->addTestCase(new Doctrine_ValidatorTestCase());
$test->addTestCase(new Doctrine_Collection_OffsetTestCase());
$test->addTestCase(new Doctrine_PessimisticLockingTestCase());
......@@ -71,12 +76,10 @@ $test->addTestCase(new Doctrine_SchemaTestCase());
$test->addTestCase(new Doctrine_ImportTestCase());
$test->addTestCase(new Doctrine_ValidatorTestCase());
$test->addTestCase(new Doctrine_CollectionTestCase());
$test->addTestCase(new Doctrine_QueryTestCase());
*/
$test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase());
......
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