1<?php
2
3/**
4 * Doctrine_Ticket_428_TestCase
5 *
6 * @package     Doctrine
7 * @author      Tamcy <7am.online@gmail.com>
8 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
9 * @category    Object Relational Mapping
10 * @link        www.doctrine-project.org
11 * @since       1.0
12 * @version     $Revision$
13 */
14class Doctrine_Ticket_428_TestCase extends Doctrine_UnitTestCase
15{
16    private $_albums;
17
18    public function prepareData()
19    {
20    }
21
22    public function testInitData()
23    {
24        // Since the tests do a $this->objTable()->clear() before each method call
25        // using the User model is not recommended for this test
26        $albums = new Doctrine_Collection('Album');
27
28        $albums[0]->name = 'Revolution';
29        $albums[0]->Song[0]->title = 'Revolution';
30        $albums[0]->Song[1]->title = 'Hey Jude';
31        $albums[0]->Song[2]->title = 'Across the Universe';
32        $albums[0]->Song[3]->title = 'Michelle';
33        $albums->save();
34        $this->assertEqual(count($albums[0]->Song), 4);
35        $this->_albums = $albums;
36    }
37
38    public function testAggregateValueMappingSupportsLeftJoins()
39    {
40        foreach ($this->_albums as $album) {
41            $album->clearRelated();
42        }
43
44        $q = new Doctrine_Query();
45
46        $q->select('a.name, COUNT(s.id) count')->from('Album a')->leftJoin('a.Song s')->groupby('a.id');
47        $albums = $q->execute();
48
49        try {
50            // Collection[0] should refer to the object with aggregate value
51            $this->assertEqual($albums[0]['count'], 4);
52        } catch (Exception $e) {
53            $this->fail('count aggregate value should be available');
54        }
55    }
56}