Commit f5ae3281 authored by zYne's avatar zYne

--no commit message

--no commit message
parent b234e717
......@@ -38,7 +38,6 @@
*/
class Doctrine_Collection_Snapshot_TestCase extends Doctrine_UnitTestCase
{
public function testDiffForSimpleCollection()
{
$coll = Doctrine_Query::create()->from('User u')->orderby('u.id')->execute();
......@@ -56,9 +55,7 @@ class Doctrine_Collection_Snapshot_TestCase extends Doctrine_UnitTestCase
$this->connection->clear();
$coll = Doctrine_Query::create()->from('User u')->execute();
$this->assertEqual($coll->count(), 7);
}
public function testDiffForOneToManyRelatedCollection()
{
$q = new Doctrine_Query();
......@@ -117,6 +114,7 @@ class Doctrine_Collection_Snapshot_TestCase extends Doctrine_UnitTestCase
$user->save();
$this->assertEqual(count($user->Group->getSnapshot()), 0);
}
}
......@@ -35,8 +35,6 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
public function prepareData()
{
}
public function testInitData()
{
$users = new Doctrine_Collection('User');
......@@ -55,6 +53,7 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
$users->save();
}
public function testRecordSupportsValueMapping()
{
$record = new User();
......@@ -75,17 +74,23 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
}
$this->assertEqual($i, 3);
}
public function testAggregateValueIsMappedToNewRecordOnEmptyResultSet()
{
$this->connection->clear();
$q = new Doctrine_Query();
$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();
$this->assertEqual($users->count(), 1);
$this->assertEqual($users[0]->state(), Doctrine_Record::STATE_TCLEAN);
}
public function testAggregateValueIsMappedToRecord()
{
$q = new Doctrine_Query();
......@@ -118,6 +123,7 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($users[2]->Phonenumber[0]->count, 2);
$this->assertEqual($users[3]->Phonenumber[0]->count, 1);
}
public function testAggregateValueMappingSupportsLeftJoins2()
{
$q = new Doctrine_Query();
......@@ -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');
$users = $q->execute();
$this->assertEqual($users->count(), 2);
$this->assertEqual($users->count(), 4);
}
public function testAggregateValueMappingSupportsMultipleValues()
{
$q = new Doctrine_Query();
......
......@@ -32,6 +32,7 @@
*/
class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
{
/**
public function testAggregateFunctionWithDistinctKeyword()
{
$q = new Doctrine_Query();
......@@ -88,21 +89,23 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
} catch(Doctrine_Query_Exception $e) {
$this->pass();
}
}
*/
public function testAggregateFunctionValueHydration()
{
$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();
$this->assertEqual($users[0]->Phonenumber[0]->COUNT, 1);
$this->assertEqual($users[1]->Phonenumber[0]->COUNT, 3);
$this->assertEqual($users[2]->Phonenumber[0]->COUNT, 1);
$this->assertEqual($users[3]->Phonenumber[0]->COUNT, 1);
$this->assertEqual($users[4]->Phonenumber[0]->COUNT, 3);
}
public function testSingleComponentWithAsterisk()
......
......@@ -17,6 +17,14 @@ class GroupTest
$reporter->paintHeader();
$reporter->paintFooter();
}
public function getMessages()
{
$messages = array();
foreach($this->_testCases as $testCase) {
$messages += $testCase->getMessages();
}
return $messages;
}
public function getFailCount()
{
$fails = 0;
......@@ -53,14 +61,62 @@ class UnitTestCase
protected $_failed = 0;
protected $_messages = array();
public function assertEqual($value, $value2)
{
if ($value == $value2) {
$this->_passed++;
} 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()
{
foreach (get_class_methods($this) as $method) {
......@@ -71,6 +127,10 @@ class UnitTestCase
}
}
}
public function getMessages()
{
return $this->_messages;
}
public function getFailCount()
{
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