Commit 1eb8b54d authored by zYne's avatar zYne

lots of refactorings

parent b4bf33fc
......@@ -660,8 +660,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
}
} elseif ($rel instanceof Doctrine_Relation_ForeignKey) {
foreach ($this->data as $key => $record) {
if ($record->getState() == Doctrine_Record::STATE_TCLEAN
|| $record->getState() == Doctrine_Record::STATE_TDIRTY
if ($record->state() == Doctrine_Record::STATE_TCLEAN
|| $record->state() == Doctrine_Record::STATE_TDIRTY
) {
continue;
}
......@@ -682,8 +682,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$name = $table->getComponentName();
foreach ($this->data as $key => $record) {
if ($record->getState() == Doctrine_Record::STATE_TCLEAN
|| $record->getState() == Doctrine_Record::STATE_TDIRTY
if ($record->state() == Doctrine_Record::STATE_TCLEAN
|| $record->state() == Doctrine_Record::STATE_TDIRTY
) {
continue;
}
......
......@@ -886,7 +886,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreSave($record);
switch ($record->getState()) {
switch ($record->state()) {
case Doctrine_Record::STATE_TDIRTY:
$this->unitOfWork->insert($record);
break;
......
......@@ -157,7 +157,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
// ONE-TO-ONE relationship
$obj = $record->get($fk->getAlias());
if ($obj->getState() != Doctrine_Record::STATE_TCLEAN) {
if ($obj->state() != Doctrine_Record::STATE_TCLEAN) {
$obj->save();
}
}
......@@ -261,7 +261,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
$set[] = $name." = ?";
if ($value instanceof Doctrine_Record) {
switch ($value->getState()) {
switch ($value->state()) {
case Doctrine_Record::STATE_TCLEAN:
case Doctrine_Record::STATE_TDIRTY:
$record->save();
......
......@@ -157,7 +157,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
$seqcolName = $this->conn->quoteIdentifier($this->conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
$query = 'CREATE TABLE ' . $sequenceName . ' (' . $seqcolName . ' INTEGER PRIMARY KEY DEFAULT 0 NOT NULL)';
$this->conn->exec($query);
if ($start == 1) {
......
......@@ -186,7 +186,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
// set the default values for this record
$this->setDefaultValues();
$this->assignDefaultValues();
// listen the onCreate event
$this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onCreate($this);
......@@ -309,6 +309,24 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
{
return $this->_errorStack;
}
/**
* errorStack
* assigns / returns record errorStack
*
* @param Doctrine_Validator_ErrorStack errorStack to be assigned for this record
* @return void|Doctrine_Validator_ErrorStack returns the errorStack associated with this record
*/
public function errorStack($stack = null)
{
if($stack !== null) {
if( ! ($stack instanceof Doctrine_Validator_ErrorStack)) {
throw new Doctrine_Record_Exception('Argument should be an instance of Doctrine_Validator_ErrorStack.');
}
$this->_errorStack = $stack;
} else {
return $this->_errorStack;
}
}
/**
* setDefaultValues
* sets the default values for records internal data
......@@ -316,7 +334,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @param boolean $overwrite whether or not to overwrite the already set values
* @return boolean
*/
public function setDefaultValues($overwrite = false)
public function assignDefaultValues($overwrite = false)
{
if ( ! $this->_table->hasDefaultValues()) {
return false;
......@@ -1462,6 +1480,29 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
{
$this->_table->setEnumValues($column, $values);
}
/**
* attribute
* sets or retrieves an option
*
* @see Doctrine::ATTR_* constants availible attributes
* @param mixed $attr
* @param mixed $value
* @return mixed
*/
public function attribute($attr, $value)
{
if ($value == null) {
if (is_array($attr)) {
foreach ($attr as $k => $v) {
$this->_table->setAttribute($k, $v);
}
} else {
return $this->_table->getAttribute($attr);
}
} else {
$this->_table->setAttribute($attr, $value);
}
}
/**
* option
* sets or retrieves an option
......
......@@ -260,7 +260,16 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
}
}
};
/**
if ( ! isset($definition['values'])) {
throw new Doctrine_Table_Exception('No values set for enum column ' . $name);
}
if ( ! is_array($definition['values'])) {
throw new Doctrine_Table_Exception('Enum column values should be specified as an array.');
}
*/
if ($this->getAttribute(Doctrine::ATTR_CREATE_TABLES)) {
$this->export();
}
......@@ -276,7 +285,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
array_pop($names);
$this->parents = $names;
$this->query = "SELECT ".implode(", ",array_keys($this->columns))." FROM ".$this->getTableName();
$this->query = 'SELECT ' . implode(', ', array_keys($this->columns)) . ' FROM ' . $this->getTableName();
// check if an instance of this table is already initialized
if ( ! $this->conn->addTable($this)) {
......@@ -294,35 +303,44 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
* false if table already existed in the database
*/
public function export() {
if (Doctrine::isValidClassname($this->options['declaringClass']->getName())) {
try {
$columns = array();
$primary = array();
foreach ($this->columns as $name => $column) {
$definition = $column[2];
$definition['type'] = $column[0];
$definition['length'] = $column[1];
if ($definition['type'] == 'enum' && isset($definition['default'])) {
$definition['default'] = $this->enumIndex($name, $definition['default']);
}
if ($definition['type'] == 'boolean' && isset($definition['default'])) {
$definition['default'] = (int) $definition['default'];
}
$columns[$name] = $definition;
if(isset($definition['primary']) && $definition['primary']) {
$primary[] = $name;
}
}
$options['primary'] = $primary;
if ( ! Doctrine::isValidClassname($this->options['declaringClass']->getName())) {
throw new Doctrine_Table_Exception('Class name not valid.');
}
$this->conn->export->createTable($this->options['tableName'], $columns, array_merge($this->options, $options));
} catch(Doctrine_Connection_Exception $e) {
// we only want to silence table already exists errors
if($e->getPortableCode() !== Doctrine::ERR_ALREADY_EXISTS) {
throw $e;
try {
$columns = array();
$primary = array();
foreach ($this->columns as $name => $column) {
$definition = $column[2];
$definition['type'] = $column[0];
$definition['length'] = $column[1];
switch ($definition['type']) {
case 'enum':
if (isset($definition['default'])) {
$definition['default'] = $this->enumIndex($name, $definition['default']);
}
break;
case 'boolean':
if (isset($definition['default'])) {
$definition['default'] = (int) $definition['default'];
}
break;
}
$columns[$name] = $definition;
if(isset($definition['primary']) && $definition['primary']) {
$primary[] = $name;
}
}
$options['primary'] = $primary;
$this->conn->export->createTable($this->options['tableName'], $columns, array_merge($this->options, $options));
} catch(Doctrine_Connection_Exception $e) {
// we only want to silence table already exists errors
if($e->getPortableCode() !== Doctrine::ERR_ALREADY_EXISTS) {
throw $e;
}
}
}
......@@ -902,12 +920,12 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$id = array_values($id);
}
$query = $this->query." WHERE ".implode(" = ? AND ",$this->primaryKeys)." = ?";
$query = $this->query . ' WHERE ' . implode(' = ? AND ', $this->primaryKeys) . ' = ?';
$query = $this->applyInheritance($query);
$params = array_merge($id, array_values($this->options['inheritanceMap']));
$stmt = $this->conn->execute($query,$params);
$stmt = $this->conn->execute($query, $params);
$this->data = $stmt->fetch(PDO::FETCH_ASSOC);
......@@ -928,10 +946,10 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
if ( ! empty($this->options['inheritanceMap'])) {
$a = array();
foreach ($this->options['inheritanceMap'] as $field => $value) {
$a[] = $field." = ?";
$a[] = $field . ' = ?';
}
$i = implode(" AND ",$a);
$where .= " AND $i";
$i = implode(' AND ', $a);
$where .= ' AND ' . $i;
}
return $where;
}
......@@ -1017,7 +1035,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
final public function getProxy($id = null)
{
if ($id !== null) {
$query = "SELECT ".implode(", ",$this->primaryKeys)." FROM ".$this->getTableName()." WHERE ".implode(" = ? && ",$this->primaryKeys)." = ?";
$query = 'SELECT ' . implode(', ',$this->primaryKeys)
. ' FROM ' . $this->getTableName()
. ' WHERE ' . implode(' = ? && ',$this->primaryKeys).' = ?';
$query = $this->applyInheritance($query);
$params = array_merge(array($id), array_values($this->options['inheritanceMap']));
......@@ -1104,12 +1124,29 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
* @param integer $index
* @return mixed
*/
final public function enumValue($field, $index)
public function enumValue($field, $index)
{
if ($index instanceof Doctrine_Null)
return $index;
return isset($this->options['enumMap'][$field][$index]) ? $this->options['enumMap'][$field][$index] : $index;
return isset($this->columns[$field][2]['values'][$index]) ? $this->columns[$field][2]['values'][$index] : $index;
}
/**
* enumIndex
*
* @param string $field
* @param mixed $value
* @return mixed
*/
public function enumIndex($field, $value)
{
if ( ! isset($this->columns[$field][2]['values'])) {
$values = array();
} else {
$values = $this->columns[$field][2]['values'];
}
return array_search($value, $values);
}
/**
* invokeSet
......@@ -1155,23 +1192,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
return $value;
}
/**
* enumIndex
*
* @param string $field
* @param mixed $value
* @return mixed
*/
final public function enumIndex($field, $value)
{
if ( ! isset($this->options['enumMap'][$field])) {
$values = array();
} else {
$values = $this->options['enumMap'][$field];
}
return array_search($value, $values);
}
/**
* getDefinitionOf
*
......
......@@ -53,7 +53,7 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
*/
public function setTableDefinition()
{
if ($root = $this->getAttribute('root_column_name')) {
if ($root = $this->getAttribute('rootColumnName')) {
$this->table->setColumn($root, 'integer', 11);
}
......@@ -207,7 +207,7 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
public function getMaxRootId()
{
$component = $this->table->getComponentName();
$column = $this->getAttribute('root_column_name');
$column = $this->getAttribute('rootColumnName');
// cannot get this dql to work, cannot retrieve result using $coll[0]->max
//$dql = "SELECT MAX(c.$column) FROM $component c";
......@@ -229,10 +229,10 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
* @param object $query Doctrine_Query
* @param integer $root_id id of destination root
* @return object Doctrine_Query
*/
*/
public function returnQueryWithRootId($query, $rootId = 1)
{
if ($root = $this->getAttribute('root_column_name')) {
if ($root = $this->getAttribute('rootColumnName')) {
$query->addWhere($root . ' = ?', $rootId);
}
......
......@@ -42,7 +42,7 @@ class Doctrine_Boolean_TestCase extends Doctrine_UnitTestCase {
$test->is_working = false;
$this->assertEqual($test->is_working, false);
$this->assertEqual($test->getState(), Doctrine_Record::STATE_TDIRTY);
$this->assertEqual($test->state(), Doctrine_Record::STATE_TDIRTY);
$test->save();
$test->refresh();
......@@ -98,7 +98,7 @@ class Doctrine_Boolean_TestCase extends Doctrine_UnitTestCase {
$this->is_working = null;
$this->assertEqual($this->is_working, null);
$this->assertEqual($test->getState(), Doctrine_Record::STATE_TDIRTY);
$this->assertEqual($test->state(), Doctrine_Record::STATE_TDIRTY);
$test->save();
$test->refresh();
......@@ -108,7 +108,7 @@ class Doctrine_Boolean_TestCase extends Doctrine_UnitTestCase {
$this->is_working_notnull = null;
$this->assertEqual($this->is_working_notnull, false);
$this->assertEqual($test->getState(), Doctrine_Record::STATE_TDIRTY);
$this->assertEqual($test->state(), Doctrine_Record::STATE_TDIRTY);
$test->save();
$test->refresh();
......
......@@ -240,7 +240,7 @@ class Doctrine_Collection_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual(count($coll), 3);
$this->assertEqual($coll[2]->getState(), Doctrine_Record::STATE_PROXY);
$this->assertEqual($coll[2]->state(), Doctrine_Record::STATE_PROXY);
......@@ -268,33 +268,33 @@ class Doctrine_Collection_TestCase extends Doctrine_UnitTestCase {
}
public function testFetchCollectionWithIdAsIndex() {
$user = new User();
$user->setAttribute(Doctrine::ATTR_COLL_KEY, 'id');
$user->attribute(Doctrine::ATTR_COLL_KEY, 'id');
$users = $user->getTable()->findAll();
$this->assertFalse($users->contains(0));
$this->assertEqual($users->count(), 8);
$this->assertEqual($users[0]->getState(), Doctrine_Record::STATE_TCLEAN);
$this->assertEqual($users[4]->getState(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($users[0]->state(), Doctrine_Record::STATE_TCLEAN);
$this->assertEqual($users[4]->state(), Doctrine_Record::STATE_CLEAN);
}
public function testFetchCollectionWithNameAsIndex() {
$user = new User();
$user->setAttribute(Doctrine::ATTR_COLL_KEY, 'name');
$user->attribute(Doctrine::ATTR_COLL_KEY, 'name');
$users = $user->getTable()->findAll();
$this->assertFalse($users->contains(0));
$this->assertEqual($users->count(), 8);
$this->assertEqual($users[0]->getState(), Doctrine_Record::STATE_TCLEAN);
$this->assertEqual($users['zYne']->getState(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($users[0]->state(), Doctrine_Record::STATE_TCLEAN);
$this->assertEqual($users['zYne']->state(), Doctrine_Record::STATE_CLEAN);
}
public function testFetchMultipleCollections() {
$this->connection->clear();
$user = new User();
$user->setAttribute(Doctrine::ATTR_COLL_KEY, 'id');
$user->attribute(Doctrine::ATTR_COLL_KEY, 'id');
$phonenumber = new Phonenumber();
$phonenumber->setAttribute(Doctrine::ATTR_COLL_KEY, 'id');
$phonenumber->attribute(Doctrine::ATTR_COLL_KEY, 'id');
$q = new Doctrine_Query();
......@@ -302,16 +302,16 @@ class Doctrine_Collection_TestCase extends Doctrine_UnitTestCase {
$this->assertFalse($users->contains(0));
$this->assertEqual($users->count(), 8);
$this->assertEqual($users[0]->getState(), Doctrine_Record::STATE_TCLEAN);
$this->assertEqual($users[2]->getState(), Doctrine_Record::STATE_TCLEAN);
$this->assertEqual($users[3]->getState(), Doctrine_Record::STATE_TCLEAN);
$this->assertEqual($users[4]->getState(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($users[0]->state(), Doctrine_Record::STATE_TCLEAN);
$this->assertEqual($users[2]->state(), Doctrine_Record::STATE_TCLEAN);
$this->assertEqual($users[3]->state(), Doctrine_Record::STATE_TCLEAN);
$this->assertEqual($users[4]->state(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($users[4]->name, 'zYne');
$this->assertEqual($users[4]->Phonenumber[0]->exists(), false);
$this->assertEqual($users[4]->Phonenumber[0]->getState(), Doctrine_Record::STATE_TDIRTY);
$this->assertEqual($users[4]->Phonenumber[0]->state(), Doctrine_Record::STATE_TDIRTY);
$this->assertEqual($users[4]->Phonenumber[1]->exists(), false);
$this->assertEqual($users[4]->Phonenumber[2]->getState(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($users[4]->Phonenumber[2]->state(), Doctrine_Record::STATE_CLEAN);
}
}
......
......@@ -135,7 +135,7 @@ class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase {
public function testDelete() {
$user = $this->connection->create('User');
$this->connection->delete($user);
$this->assertEqual($user->getState(),Doctrine_Record::STATE_TCLEAN);
$this->assertEqual($user->state(),Doctrine_Record::STATE_TCLEAN);
}
public function testGetTable() {
$table = $this->connection->getTable('Group');
......
......@@ -17,7 +17,7 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($this->profiler->lastEvent()->getQuery(), 'CREATE TABLE test (id INT)');
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::QUERY);
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::QUERY);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$this->assertEqual($this->dbh->count(), 1);
......@@ -29,14 +29,14 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($event->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::PREPARE);
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::PREPARE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$stmt->execute(array(1));
$this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::EXECUTE);
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::EXECUTE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$this->assertEqual($this->dbh->count(), 2);
......@@ -46,13 +46,13 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
$stmt = $this->dbh->prepare('INSERT INTO test (id) VALUES (?)');
$this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::PREPARE);
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::PREPARE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$stmt2 = $this->dbh->prepare('INSERT INTO test (id) VALUES (?)');
$this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::PREPARE);
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::PREPARE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$stmt->execute(array(1));
......@@ -60,7 +60,7 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::EXECUTE);
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::EXECUTE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$this->assertEqual($this->dbh->count(), 4);
......@@ -77,12 +77,12 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
}
$this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::EXECUTE);
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::EXECUTE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::EXECUTE);
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::EXECUTE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
}
public function testTransactionRollback() {
......@@ -94,7 +94,7 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
}
$this->assertEqual($this->profiler->lastEvent()->getQuery(), null);
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::BEGIN);
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::BEGIN);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
try {
......@@ -106,7 +106,7 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($this->profiler->lastEvent()->getQuery(), null);
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::ROLLBACK);
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::ROLLBACK);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
}
public function testTransactionCommit() {
......@@ -118,7 +118,7 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
}
$this->assertEqual($this->profiler->lastEvent()->getQuery(), null);
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::BEGIN);
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::BEGIN);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
try {
......@@ -131,7 +131,7 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($this->profiler->lastEvent()->getQuery(), null);
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::COMMIT);
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::COMMIT);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
}
}
......
......@@ -29,7 +29,7 @@
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
*/
class Doctrine_EventListener_Chain_TestCase extends Doctrine_UnitTestCase {
public function testAccessorInvokerChain() {
......@@ -79,7 +79,7 @@ class EventListenerChainTest extends Doctrine_Record {
$chain = new Doctrine_EventListener_Chain();
$chain->add(new Doctrine_EventListener_TestA());
$chain->add(new Doctrine_EventListener_TestB());
$this->setAttribute(Doctrine::ATTR_LISTENER, $chain);
$this->attribute(Doctrine::ATTR_LISTENER, $chain);
}
}
......
......@@ -38,7 +38,7 @@ class EventListenerChainTest extends Doctrine_Record {
$chain = new Doctrine_EventListener_Chain();
$chain->add(new Doctrine_EventListener_TestA());
$chain->add(new Doctrine_EventListener_TestB());
$this->setAttribute(Doctrine::ATTR_LISTENER, $chain);
$this->attribute(Doctrine::ATTR_LISTENER, $chain);
}
}
......
......@@ -36,7 +36,7 @@ class EventListenerTest extends Doctrine_Record {
$this->hasColumn("password", "string", 8);
}
public function setUp() {
$this->setAttribute(Doctrine::ATTR_LISTENER, new Doctrine_EventListener_AccessorInvoker());
$this->attribute(Doctrine::ATTR_LISTENER, new Doctrine_EventListener_AccessorInvoker());
}
public function getName($name) {
return strtoupper($name);
......
......@@ -524,14 +524,14 @@ class Doctrine_Query_TestCase extends Doctrine_UnitTestCase {
$query->from("Task-l:ResourceAlias-l");
$tasks = $query->execute();
$this->assertEqual($tasks->count(), 3);
$this->assertTrue($tasks instanceof Doctrine_Collection_Lazy);
$this->assertTrue($tasks instanceof Doctrine_Collection);
$this->assertEqual($tasks[0]->ResourceAlias->count(), 2);
$this->assertTrue($tasks[0]->ResourceAlias instanceof Doctrine_Collection_Lazy);
$this->assertTrue($tasks[0]->ResourceAlias instanceof Doctrine_Collection);
$this->assertEqual($tasks[1]->ResourceAlias->count(), 4);
$this->assertTrue($tasks[1]->ResourceAlias instanceof Doctrine_Collection_Lazy);
$this->assertTrue($tasks[1]->ResourceAlias instanceof Doctrine_Collection);
// sanity checking
$this->assertEqual($tasks[1]->ResourceAlias[0]->getState(), Doctrine_Record::STATE_PROXY);
$this->assertEqual($tasks[1]->ResourceAlias[1]->getState(), Doctrine_Record::STATE_PROXY);
......@@ -548,7 +548,7 @@ class Doctrine_Query_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual(count($this->dbh), ($count + 4));
$this->assertEqual($tasks[2]->ResourceAlias->count(), 1);
$this->assertTrue($tasks[2]->ResourceAlias instanceof Doctrine_Collection_Lazy);
$this->assertTrue($tasks[2]->ResourceAlias instanceof Doctrine_Collection);
}
public function testManyToManyFetchingWithDotOperator() {
......@@ -560,16 +560,16 @@ class Doctrine_Query_TestCase extends Doctrine_UnitTestCase {
$tasks = $query->query("FROM Task-l.ResourceAlias-l");
$this->assertEqual($tasks->count(), 4);
$this->assertTrue($tasks instanceof Doctrine_Collection_Lazy);
$this->assertTrue($tasks instanceof Doctrine_Collection);
$this->assertEqual($tasks[0]->ResourceAlias->count(), 2);
$this->assertTrue($tasks[0]->ResourceAlias instanceof Doctrine_Collection_Lazy);
$this->assertTrue($tasks[0]->ResourceAlias instanceof Doctrine_Collection);
$this->assertEqual($tasks[1]->ResourceAlias->count(), 4);
$this->assertTrue($tasks[1]->ResourceAlias instanceof Doctrine_Collection_Lazy);
$this->assertTrue($tasks[1]->ResourceAlias instanceof Doctrine_Collection);
$this->assertEqual($tasks[1]->ResourceAlias->count(), 4);
$this->assertTrue($tasks[1]->ResourceAlias instanceof Doctrine_Collection_Lazy);
$this->assertTrue($tasks[1]->ResourceAlias instanceof Doctrine_Collection);
// sanity checking
$this->assertEqual($tasks[1]->ResourceAlias[0]->getState(), Doctrine_Record::STATE_PROXY);
$this->assertEqual($tasks[1]->ResourceAlias[1]->getState(), Doctrine_Record::STATE_PROXY);
......@@ -586,7 +586,7 @@ class Doctrine_Query_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual(count($this->dbh), ($count + 4));
$this->assertEqual($tasks[2]->ResourceAlias->count(), 1);
$this->assertTrue($tasks[2]->ResourceAlias instanceof Doctrine_Collection_Lazy);
$this->assertTrue($tasks[2]->ResourceAlias instanceof Doctrine_Collection);
$this->assertEqual($tasks[3]->ResourceAlias->count(), 0);
$this->assertTrue($tasks[3]->ResourceAlias instanceof Doctrine_Collection);
......@@ -597,16 +597,16 @@ class Doctrine_Query_TestCase extends Doctrine_UnitTestCase {
$tasks = $query->query("FROM Task-l.ResourceAlias-l");
$this->assertEqual($tasks->count(), 4);
$this->assertTrue($tasks instanceof Doctrine_Collection_Lazy);
$this->assertTrue($tasks instanceof Doctrine_Collection);
$this->assertEqual($tasks[0]->ResourceAlias->count(), 2);
$this->assertTrue($tasks[0]->ResourceAlias instanceof Doctrine_Collection_Lazy);
$this->assertTrue($tasks[0]->ResourceAlias instanceof Doctrine_Collection);
$this->assertEqual($tasks[1]->ResourceAlias->count(), 4);
$this->assertTrue($tasks[1]->ResourceAlias instanceof Doctrine_Collection_Lazy);
$this->assertTrue($tasks[1]->ResourceAlias instanceof Doctrine_Collection);
$this->assertEqual($tasks[1]->ResourceAlias->count(), 4);
$this->assertTrue($tasks[1]->ResourceAlias instanceof Doctrine_Collection_Lazy);
$this->assertTrue($tasks[1]->ResourceAlias instanceof Doctrine_Collection);
// sanity checking
$this->assertEqual($tasks[1]->ResourceAlias[0]->getState(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($tasks[1]->ResourceAlias[1]->getState(), Doctrine_Record::STATE_CLEAN);
......@@ -623,7 +623,7 @@ class Doctrine_Query_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual(count($this->dbh), $count);
$this->assertEqual($tasks[2]->ResourceAlias->count(), 1);
$this->assertTrue($tasks[2]->ResourceAlias instanceof Doctrine_Collection_Lazy);
$this->assertTrue($tasks[2]->ResourceAlias instanceof Doctrine_Collection);
$this->assertEqual($tasks[3]->ResourceAlias->count(), 0);
$this->assertTrue($tasks[3]->ResourceAlias instanceof Doctrine_Collection);
......@@ -755,7 +755,7 @@ class Doctrine_Query_TestCase extends Doctrine_UnitTestCase {
$q->from("User-l(name, email_id)");
$users = $q->execute();
$this->assertEqual($users->count(), 8);
$this->assertTrue($users instanceof Doctrine_Collection_Lazy);
$this->assertTrue($users instanceof Doctrine_Collection);
$count = count($this->dbh);
$this->assertTrue(is_string($users[0]->name));
$this->assertEqual($count, count($this->dbh));
......@@ -768,7 +768,7 @@ class Doctrine_Query_TestCase extends Doctrine_UnitTestCase {
$q->from("User-b(name, email_id)");
$users = $q->execute();
$this->assertEqual($users->count(), 8);
$this->assertTrue($users instanceof Doctrine_Collection_Batch);
$this->assertTrue($users instanceof Doctrine_Collection);
$count = count($this->dbh);
$this->assertTrue(is_string($users[0]->name));
$this->assertEqual($count, count($this->dbh));
......@@ -830,7 +830,7 @@ class Doctrine_Query_TestCase extends Doctrine_UnitTestCase {
$count = $this->dbh->count();
$users = $this->query->from("User-l:Email-i")->execute();
$this->assertEqual(($count + 1), $this->dbh->count());
$this->assertTrue($users instanceof Doctrine_Collection_Lazy);
$this->assertTrue($users instanceof Doctrine_Collection);
$count = $this->dbh->count();
foreach($users as $user) {
......@@ -858,7 +858,7 @@ class Doctrine_Query_TestCase extends Doctrine_UnitTestCase {
$count = $this->dbh->count();
$users = $this->query->from("User-l:Account-i")->execute();
$this->assertEqual(($count + 1), $this->dbh->count());
$this->assertTrue($users instanceof Doctrine_Collection_Lazy);
$this->assertTrue($users instanceof Doctrine_Collection);
$this->assertEqual($users->count(), 1);
$this->assertEqual($users[0]->Account->amount,3000);
......@@ -1003,7 +1003,7 @@ class Doctrine_Query_TestCase extends Doctrine_UnitTestCase {
$this->assertFalse(strpos($query->getQuery(),"LIMIT"));
$coll = $query->execute();
$this->assertTrue($coll instanceof Doctrine_Collection_Lazy);
$this->assertTrue($coll instanceof Doctrine_Collection);
$this->assertEqual($coll->count(), 1);
......@@ -1054,7 +1054,7 @@ class Doctrine_Query_TestCase extends Doctrine_UnitTestCase {
"SELECT e.id AS e__id FROM entity e WHERE (e.type = 0)");
$this->assertEqual($users[0]->name, "zYne");
$this->assertTrue($users instanceof Doctrine_Collection_Lazy);
$this->assertTrue($users instanceof Doctrine_Collection);
}
......
......@@ -49,8 +49,8 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($coll->count(), 11);
$this->assertEqual($coll[0]->getState(), Doctrine_Record::STATE_PROXY);
$this->assertEqual($coll[3]->getState(), Doctrine_Record::STATE_PROXY);
$this->assertEqual($coll[0]->state(), Doctrine_Record::STATE_PROXY);
$this->assertEqual($coll[3]->state(), Doctrine_Record::STATE_PROXY);
}
public function testSmartMapping() {
......@@ -66,8 +66,8 @@ class Doctrine_RawSql_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($coll->count(), 11);
$this->assertEqual($coll[0]->getState(), Doctrine_Record::STATE_PROXY);
$this->assertEqual($coll[3]->getState(), Doctrine_Record::STATE_PROXY);
$this->assertEqual($coll[0]->state(), Doctrine_Record::STATE_PROXY);
$this->assertEqual($coll[3]->state(), Doctrine_Record::STATE_PROXY);
}
public function testMultipleComponents() {
......
This diff is collapsed.
......@@ -135,7 +135,7 @@ class Doctrine_Table_TestCase extends Doctrine_UnitTestCase {
public function testCreate() {
$record = $this->objTable->create();
$this->assertTrue($record instanceof Doctrine_Record);
$this->assertTrue($record->getState() == Doctrine_Record::STATE_TCLEAN);
$this->assertTrue($record->state() == Doctrine_Record::STATE_TCLEAN);
}
public function testFind() {
$record = $this->objTable->find(4);
......
......@@ -119,7 +119,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
$validator = new Doctrine_Validator();
$validator->validateRecord($test);
$stack = $test->getErrorStack();
$stack = $test->errorStack();
$this->assertTrue($stack instanceof Doctrine_Validator_ErrorStack);
......@@ -137,15 +137,15 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
* Tests Doctrine_Validator::validateRecord()
*/
public function testValidate() {
$user = $this->connection->getTable("User")->find(4);
$user = $this->connection->getTable('User')->find(4);
$set = array("password" => "this is an example of too long password",
"loginname" => "this is an example of too long loginname",
"name" => "valid name",
"created" => "invalid");
$set = array('password' => 'this is an example of too long password',
'loginname' => 'this is an example of too long loginname',
'name' => 'valid name',
'created' => 'invalid');
$user->setArray($set);
$email = $user->Email;
$email->address = "zYne@invalid";
$email->address = 'zYne@invalid';
$this->assertTrue($user->getModified() == $set);
......@@ -153,7 +153,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
$validator->validateRecord($user);
$stack = $user->getErrorStack();
$stack = $user->errorStack();
$this->assertTrue($stack instanceof Doctrine_Validator_ErrorStack);
$this->assertTrue(in_array('length', $stack['loginname']));
......@@ -161,12 +161,12 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
$this->assertTrue(in_array('type', $stack['created']));
$validator->validateRecord($email);
$stack = $email->getErrorStack();
$stack = $email->errorStack();
$this->assertTrue(in_array('email', $stack['address']));
$email->address = "arnold@example.com";
$email->address = 'arnold@example.com';
$validator->validateRecord($email);
$stack = $email->getErrorStack();
$stack = $email->errorStack();
$this->assertTrue(in_array('unique', $stack['address']));
}
......@@ -205,7 +205,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($e->count(), 1);
$invalidRecords = $e->getInvalidRecords();
$this->assertEqual(count($invalidRecords), 1);
$stack = $invalidRecords[0]->getErrorStack();
$stack = $invalidRecords[0]->errorStack();
$this->assertTrue(in_array('length', $stack['name']));
}
......@@ -222,8 +222,8 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
$this->assertTrue(is_array($a));
$emailStack = $a[array_search($user->Email, $a)]->getErrorStack();
$userStack = $a[array_search($user, $a)]->getErrorStack();
$emailStack = $a[array_search($user->Email, $a)]->errorStack();
$userStack = $a[array_search($user, $a)]->errorStack();
$this->assertTrue(in_array('email', $emailStack['address']));
$this->assertTrue(in_array('length', $userStack['name']));
......@@ -247,8 +247,8 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($e->count(), 1);
$invalidRecords = $e->getInvalidRecords();
$this->assertEqual(count($invalidRecords), 1);
$stack = $invalidRecords[0]->getErrorStack();
$stack = $invalidRecords[0]->errorStack();
$this->assertEqual($stack->count(), 2);
$this->assertTrue(in_array('notTheSaint', $stack['name'])); // validate() hook constraint
......@@ -267,7 +267,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
$invalidRecords = $e->getInvalidRecords();
$this->assertEqual(count($invalidRecords), 1);
$stack = $invalidRecords[0]->getErrorStack();
$stack = $invalidRecords[0]->errorStack();
$this->assertEqual($stack->count(), 1);
$this->assertTrue(in_array('notNobody', $stack['loginname'])); // validateOnUpdate() hook constraint
......@@ -290,7 +290,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase {
$user->save();
$this->fail();
} catch (Doctrine_Validator_Exception $ex) {
$errors = $user->getErrorStack();
$errors = $user->errorStack();
$this->assertTrue(in_array('pwNotTopSecret', $errors['password']));
}
......
......@@ -56,7 +56,7 @@ class Doctrine_View_TestCase extends Doctrine_UnitTestCase {
$this->assertTrue($users instanceof Doctrine_Collection);
$this->assertEqual($users->count(), 8);
$this->assertEqual($users[0]->name, 'zYne');
$this->assertEqual($users[0]->getState(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($users[0]->state(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($count, $this->dbh->count());
$success = true;
......
This diff is collapsed.
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