Commit f5ae3281 authored by zYne's avatar zYne

--no commit message

--no commit message
parent b234e717
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
*/ */
class Doctrine_Collection_Snapshot_TestCase extends Doctrine_UnitTestCase class Doctrine_Collection_Snapshot_TestCase extends Doctrine_UnitTestCase
{ {
public function testDiffForSimpleCollection() public function testDiffForSimpleCollection()
{ {
$coll = Doctrine_Query::create()->from('User u')->orderby('u.id')->execute(); $coll = Doctrine_Query::create()->from('User u')->orderby('u.id')->execute();
...@@ -56,9 +55,7 @@ class Doctrine_Collection_Snapshot_TestCase extends Doctrine_UnitTestCase ...@@ -56,9 +55,7 @@ class Doctrine_Collection_Snapshot_TestCase extends Doctrine_UnitTestCase
$this->connection->clear(); $this->connection->clear();
$coll = Doctrine_Query::create()->from('User u')->execute(); $coll = Doctrine_Query::create()->from('User u')->execute();
$this->assertEqual($coll->count(), 7); $this->assertEqual($coll->count(), 7);
} }
public function testDiffForOneToManyRelatedCollection() public function testDiffForOneToManyRelatedCollection()
{ {
$q = new Doctrine_Query(); $q = new Doctrine_Query();
...@@ -117,6 +114,7 @@ class Doctrine_Collection_Snapshot_TestCase extends Doctrine_UnitTestCase ...@@ -117,6 +114,7 @@ class Doctrine_Collection_Snapshot_TestCase extends Doctrine_UnitTestCase
$user->save(); $user->save();
$this->assertEqual(count($user->Group->getSnapshot()), 0); $this->assertEqual(count($user->Group->getSnapshot()), 0);
} }
} }
...@@ -35,8 +35,6 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase ...@@ -35,8 +35,6 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
public function prepareData() public function prepareData()
{ {
} }
public function testInitData() public function testInitData()
{ {
$users = new Doctrine_Collection('User'); $users = new Doctrine_Collection('User');
...@@ -55,6 +53,7 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase ...@@ -55,6 +53,7 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
$users->save(); $users->save();
} }
public function testRecordSupportsValueMapping() public function testRecordSupportsValueMapping()
{ {
$record = new User(); $record = new User();
...@@ -75,17 +74,23 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase ...@@ -75,17 +74,23 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
} }
$this->assertEqual($i, 3); $this->assertEqual($i, 3);
} }
public function testAggregateValueIsMappedToNewRecordOnEmptyResultSet() public function testAggregateValueIsMappedToNewRecordOnEmptyResultSet()
{ {
$this->connection->clear();
$q = new Doctrine_Query(); $q = new Doctrine_Query();
$q->select('COUNT(u.id) count')->from('User u'); $q->select('COUNT(u.id) count')->from('User u');
$this->assertEqual($q->getSql(), "SELECT COUNT(e.id) AS e__0 FROM entity e WHERE (e.type = 0)");
$users = $q->execute(); $users = $q->execute();
$this->assertEqual($users->count(), 1); $this->assertEqual($users->count(), 1);
$this->assertEqual($users[0]->state(), Doctrine_Record::STATE_TCLEAN); $this->assertEqual($users[0]->state(), Doctrine_Record::STATE_TCLEAN);
} }
public function testAggregateValueIsMappedToRecord() public function testAggregateValueIsMappedToRecord()
{ {
$q = new Doctrine_Query(); $q = new Doctrine_Query();
...@@ -118,6 +123,7 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase ...@@ -118,6 +123,7 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($users[2]->Phonenumber[0]->count, 2); $this->assertEqual($users[2]->Phonenumber[0]->count, 2);
$this->assertEqual($users[3]->Phonenumber[0]->count, 1); $this->assertEqual($users[3]->Phonenumber[0]->count, 1);
} }
public function testAggregateValueMappingSupportsLeftJoins2() public function testAggregateValueMappingSupportsLeftJoins2()
{ {
$q = new Doctrine_Query(); $q = new Doctrine_Query();
...@@ -127,8 +133,9 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase ...@@ -127,8 +133,9 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($q->getQuery(), 'SELECT MAX(e.name) AS e__0 FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0) GROUP BY e.id'); $this->assertEqual($q->getQuery(), 'SELECT MAX(e.name) AS e__0 FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0) GROUP BY e.id');
$users = $q->execute(); $users = $q->execute();
$this->assertEqual($users->count(), 2); $this->assertEqual($users->count(), 4);
} }
public function testAggregateValueMappingSupportsMultipleValues() public function testAggregateValueMappingSupportsMultipleValues()
{ {
$q = new Doctrine_Query(); $q = new Doctrine_Query();
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
*/ */
class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
{ {
/**
public function testAggregateFunctionWithDistinctKeyword() public function testAggregateFunctionWithDistinctKeyword()
{ {
$q = new Doctrine_Query(); $q = new Doctrine_Query();
...@@ -88,21 +89,23 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase ...@@ -88,21 +89,23 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
} catch(Doctrine_Query_Exception $e) { } catch(Doctrine_Query_Exception $e) {
$this->pass(); $this->pass();
} }
} }
*/
public function testAggregateFunctionValueHydration() public function testAggregateFunctionValueHydration()
{ {
$q = new Doctrine_Query(); $q = new Doctrine_Query();
$q->parseQuery('SELECT u.id, COUNT(p.id) FROM User u, u.Phonenumber p GROUP BY u.id'); $q->parseQuery('SELECT u.id, COUNT(p.id) FROM User u LEFT JOIN u.Phonenumber p GROUP BY u.id');
$users = $q->execute(); $users = $q->execute();
$this->assertEqual($users[0]->Phonenumber[0]->COUNT, 1); $this->assertEqual($users[0]->Phonenumber[0]->COUNT, 1);
$this->assertEqual($users[1]->Phonenumber[0]->COUNT, 3); $this->assertEqual($users[1]->Phonenumber[0]->COUNT, 3);
$this->assertEqual($users[2]->Phonenumber[0]->COUNT, 1); $this->assertEqual($users[2]->Phonenumber[0]->COUNT, 1);
$this->assertEqual($users[3]->Phonenumber[0]->COUNT, 1); $this->assertEqual($users[3]->Phonenumber[0]->COUNT, 1);
$this->assertEqual($users[4]->Phonenumber[0]->COUNT, 3); $this->assertEqual($users[4]->Phonenumber[0]->COUNT, 3);
} }
public function testSingleComponentWithAsterisk() public function testSingleComponentWithAsterisk()
......
...@@ -17,6 +17,14 @@ class GroupTest ...@@ -17,6 +17,14 @@ class GroupTest
$reporter->paintHeader(); $reporter->paintHeader();
$reporter->paintFooter(); $reporter->paintFooter();
} }
public function getMessages()
{
$messages = array();
foreach($this->_testCases as $testCase) {
$messages += $testCase->getMessages();
}
return $messages;
}
public function getFailCount() public function getFailCount()
{ {
$fails = 0; $fails = 0;
...@@ -53,14 +61,62 @@ class UnitTestCase ...@@ -53,14 +61,62 @@ class UnitTestCase
protected $_failed = 0; protected $_failed = 0;
protected $_messages = array();
public function assertEqual($value, $value2) public function assertEqual($value, $value2)
{ {
if ($value == $value2) { if ($value == $value2) {
$this->_passed++; $this->_passed++;
} else { } else {
$this->_failed++; $this->fail();
}
}
public function assertNotEqual($value, $value2)
{
if ($value != $value2) {
$this->_passed++;
} else {
$this->fail();
}
}
public function assertTrue($expr)
{
if ($expr) {
$this->_passed++;
} else {
$this->fail();
}
}
public function assertFalse($expr)
{
if ( ! $expr) {
$this->_passed++;
} else {
$this->fail();
} }
} }
public function pass()
{
$this->_passed++;
}
public function fail()
{
$trace = debug_backtrace();
array_shift($trace);
foreach ($trace as $stack) {
if (substr($stack['function'], 0, 4) === 'test') {
$class = new ReflectionClass($stack['class']);
$this->_messages[] = $class->getName() . ' : method ' . $stack['function'] . ' failed on line ' . $line;
break;
}
$line = $stack['line'];
}
$this->_failed++;
}
public function run() public function run()
{ {
foreach (get_class_methods($this) as $method) { foreach (get_class_methods($this) as $method) {
...@@ -71,6 +127,10 @@ class UnitTestCase ...@@ -71,6 +127,10 @@ class UnitTestCase
} }
} }
} }
public function getMessages()
{
return $this->_messages;
}
public function getFailCount() public function getFailCount()
{ {
return $this->_failed; return $this->_failed;
......
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