From dbd49e93101e9d5043f57dbff8609d0aef873169 Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 5 Jul 2007 23:47:48 +0000 Subject: [PATCH] --- lib/Doctrine/Hook.php | 19 +++++++++---------- lib/Doctrine/Record.php | 3 +++ tests/HookTestCase.php | 2 +- tests/NewCoreTestCase.php | 2 +- tests/Query/ComponentAliasTestCase.php | 14 +++++++------- tests/Record/ZeroValuesTestCase.php | 2 +- tests/RecordTestCase.php | 4 +++- tests/Ticket364TestCase.php | 2 +- tests/run.php | 8 +++++--- 9 files changed, 31 insertions(+), 25 deletions(-) diff --git a/lib/Doctrine/Hook.php b/lib/Doctrine/Hook.php index 21ac66c5f..c365ee73b 100644 --- a/lib/Doctrine/Hook.php +++ b/lib/Doctrine/Hook.php @@ -82,6 +82,8 @@ class Doctrine_Hook } else { throw new Doctrine_Exception('Constructor argument should be either Doctrine_Query object or valid DQL query'); } + + $this->query->getQuery(); } /** * getQuery @@ -130,17 +132,16 @@ class Doctrine_Hook if (count($e) == 2) { list($alias, $column) = $e; - /** - $tableAlias = $this->query->getTableAlias($alias); + $map = $this->query->getAliasDeclaration($alias); $table = $map['table']; if ( ! $table) { - throw new Doctrine_Exception('Unknown table alias ' . $tableAlias); + throw new Doctrine_Exception('Unknown alias ' . $alias); } if ($def = $table->getDefinitionOf($column)) { - */ + $def[0] = gettype($value); if (isset($this->typeParsers[$def[0]])) { $name = $this->typeParsers[$def[0]]; @@ -150,7 +151,7 @@ class Doctrine_Hook $parser->parse($alias, $column, $value); $this->query->addWhere($parser->getCondition(), $parser->getParams()); - //} + } } } @@ -182,15 +183,13 @@ class Doctrine_Hook if (count($e) == 2) { list($alias, $column) = $e; - /** - $tableAlias = $this->query->getTableAlias($alias); + $map = $this->query->getAliasDeclaration($alias); $table = $map['table']; - if ($def = $table->getDefinitionOf($column)) { - */ + if ($def = $table->getDefinitionOf($column)) { $this->query->addOrderBy($alias . '.' . $column . ' ' . $order); - //} + } } } return true; diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index e532f2be1..6e95df9d7 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -1091,6 +1091,9 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count $a = array(); foreach ($this as $column => $value) { + if ($value === self::$_null) { + $value = null; + } $a[$column] = $value; } if ($this->_table->getIdentifierType() == Doctrine::IDENTIFIER_AUTOINC) { diff --git a/tests/HookTestCase.php b/tests/HookTestCase.php index 6ff0ae31e..7f2a7c6c6 100644 --- a/tests/HookTestCase.php +++ b/tests/HookTestCase.php @@ -115,8 +115,8 @@ class Doctrine_Hook_TestCase extends Doctrine_UnitTestCase $a['where'] = array('u.unknown' => 'Jack Daniels'); $hook->hookWhere($a['where']); - $this->assertEqual($hook->getQuery()->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0)'); + $this->assertEqual($hook->getQuery()->getSql(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0)'); } public function testEqualParserUsesEqualOperator() diff --git a/tests/NewCoreTestCase.php b/tests/NewCoreTestCase.php index 873e44004..1cf3d0202 100644 --- a/tests/NewCoreTestCase.php +++ b/tests/NewCoreTestCase.php @@ -43,6 +43,6 @@ class Doctrine_NewCore_TestCase extends Doctrine_UnitTestCase $q->load('u.Phonenumber p', false); - $this->assertEqual($q->getQueryPart('from'), array('entity e', 'LEFT JOIN phonenumber p ON e.id = p.entity_id')); + $this->assertEqual($q->getQueryPart('from'), array('entity e', 'p' => 'LEFT JOIN phonenumber p ON e.id = p.entity_id')); } } diff --git a/tests/Query/ComponentAliasTestCase.php b/tests/Query/ComponentAliasTestCase.php index 4e3668cf5..14f6f7c33 100644 --- a/tests/Query/ComponentAliasTestCase.php +++ b/tests/Query/ComponentAliasTestCase.php @@ -42,13 +42,13 @@ class Doctrine_Query_ComponentAlias_TestCase extends Doctrine_UnitTestCase $users = $q->execute(); - $count = count($this->dbh); + $count = count($this->conn); $this->assertEqual($users->count(), 8); $this->assertTrue($users[0]->Phonenumber instanceof Doctrine_Collection); $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id, p.id AS p__id, p.phonenumber AS p__phonenumber, p.entity_id AS p__entity_id FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0)"); - $this->assertEqual($count, count($this->dbh)); + $this->assertEqual($count, count($this->conn)); } public function testQueryWithNestedAliases() @@ -60,13 +60,13 @@ class Doctrine_Query_ComponentAlias_TestCase extends Doctrine_UnitTestCase $users = $q->execute(); - $count = count($this->dbh); + $count = count($this->conn); $this->assertEqual($users->count(), 8); $this->assertTrue($users[0]->Phonenumber instanceof Doctrine_Collection); $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id, e2.id AS e2__id, e2.name AS e2__name, e2.loginname AS e2__loginname, e2.password AS e2__password, e2.type AS e2__type, e2.created AS e2__created, e2.updated AS e2__updated, e2.email_id AS e2__email_id, p.id AS p__id, p.phonenumber AS p__phonenumber, p.entity_id AS p__entity_id FROM entity e LEFT JOIN groupuser g ON e.id = g.user_id LEFT JOIN entity e2 ON e2.id = g.group_id LEFT JOIN phonenumber p ON e2.id = p.entity_id WHERE (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))"); - $this->assertEqual(($count + 1), count($this->dbh)); + $this->assertEqual(($count + 1), count($this->conn)); } public function testQueryWithNestedAliasesAndArrayFetching() { @@ -77,7 +77,7 @@ class Doctrine_Query_ComponentAlias_TestCase extends Doctrine_UnitTestCase $users = $q->execute(array(), Doctrine::FETCH_ARRAY); - $count = count($this->dbh); + $count = count($this->conn); $this->assertEqual(count($users), 8); $this->assertEqual(count($users[7]['Group']), 0); @@ -93,7 +93,7 @@ class Doctrine_Query_ComponentAlias_TestCase extends Doctrine_UnitTestCase $users = $q->execute(); - $count = count($this->dbh); + $count = count($this->conn); $this->assertTrue($users[0]->Phonenumber instanceof Doctrine_Collection); @@ -104,7 +104,7 @@ class Doctrine_Query_ComponentAlias_TestCase extends Doctrine_UnitTestCase $this->assertEqual(count($users[0]['Group'][0]['Phonenumber']), 1); $this->assertEqual(count($users[1]['Group']), 0); - $this->assertEqual($count, count($this->dbh)); + $this->assertEqual($count, count($this->conn)); } public function testQueryWithMultipleNestedAliasesAndArrayFetching() diff --git a/tests/Record/ZeroValuesTestCase.php b/tests/Record/ZeroValuesTestCase.php index b0f9828db..94d305140 100644 --- a/tests/Record/ZeroValuesTestCase.php +++ b/tests/Record/ZeroValuesTestCase.php @@ -62,7 +62,7 @@ class Doctrine_Record_ZeroValues_TestCase extends Doctrine_UnitTestCase $q->from('ZeroValueTest'); $users = $q->execute(array(), Doctrine::FETCH_ARRAY); - $this->assertIdentical($users[0]['is_super_admin'], '0'); + $this->assertIdentical($users[0]['is_super_admin'], false); // check for aggregate bug $this->assertTrue( ! isset($users[0][0])); } diff --git a/tests/RecordTestCase.php b/tests/RecordTestCase.php index bb1a6fbf6..218ea08fb 100644 --- a/tests/RecordTestCase.php +++ b/tests/RecordTestCase.php @@ -117,10 +117,12 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase $this->assertTrue(is_array($a)); $this->assertTrue(array_key_exists('name', $a)); + + $this->assertEqual($a['name'], null); $this->assertTrue(array_key_exists('id', $a)); $this->assertEqual($a['id'], null); - + $user->name = 'Someone'; $user->save(); diff --git a/tests/Ticket364TestCase.php b/tests/Ticket364TestCase.php index 12495dd9d..67363976a 100644 --- a/tests/Ticket364TestCase.php +++ b/tests/Ticket364TestCase.php @@ -100,7 +100,7 @@ class Doctrine_Ticket364_TestCase extends Doctrine_UnitTestCase { $q = new Doctrine_Query(); $coll = $q->from('NestReference')->execute(array(), Doctrine::FETCH_ARRAY); - $this->assertEqual(count($coll), 2); + $this->assertEqual(count($coll), 1); } } diff --git a/tests/run.php b/tests/run.php index 1ea52707d..3eeebc60e 100644 --- a/tests/run.php +++ b/tests/run.php @@ -70,7 +70,7 @@ $test = new GroupTest('Doctrine Framework Unit Tests'); $test->addTestCase(new Doctrine_Ticket330_TestCase()); */ -/** */ +/** */ // Connection drivers (not yet fully tested) $test->addTestCase(new Doctrine_Connection_Pgsql_TestCase()); $test->addTestCase(new Doctrine_Connection_Oracle_TestCase()); @@ -155,7 +155,9 @@ $test->addTestCase(new Doctrine_Access_TestCase()); //$test->addTestCase(new Doctrine_Configurable_TestCase()); $test->addTestCase(new Doctrine_Manager_TestCase()); + $test->addTestCase(new Doctrine_Connection_TestCase()); + $test->addTestCase(new Doctrine_Table_TestCase()); @@ -319,9 +321,9 @@ $test->addTestCase(new Doctrine_Cache_Sqlite_TestCase()); $test->addTestCase(new Doctrine_Record_SaveBlankRecord_TestCase()); - /** + $test->addTestCase(new Doctrine_Template_TestCase()); - */ + /** */ //$test->addTestCase(new Doctrine_IntegrityAction_TestCase()); //$test->addTestCase(new Doctrine_AuditLog_TestCase());