Changeset 6043

Show
Ignore:
Timestamp:
07/09/09 17:56:34 (7 months ago)
Author:
jwage
Message:

[2.0] More work on the QueryBuilder? and Expr classes

Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/Doctrine/ORM/Query/Expr.php

    r6030 r6043  
    7070        'ltoet' => '_lessThanOrEqualToExpr', 
    7171        'between' => '_betweenExpr', 
    72         'trim' => '_trimExpr' 
     72        'trim' => '_trimExpr', 
     73        'on' => '_onExpr', 
     74        'with' => '_withExpr', 
     75        'from' => '_fromExpr', 
     76        'innerJoin' => '_innerJoinExpr', 
     77        'leftJoin' => '_leftJoinExpr' 
    7378    ); 
    7479 
     
    282287    } 
    283288 
     289    private function _onExpr() 
     290    { 
     291        return 'ON ' . $this->_parts[0]; 
     292    } 
     293 
     294    private function _withExpr() 
     295    { 
     296        return 'WITH ' . $this->_parts[0]; 
     297    } 
     298 
     299    private function _fromExpr() 
     300    { 
     301        return $this->_parts[0] . ' ' . $this->_parts[1]; 
     302    } 
     303 
     304    private function _leftJoinExpr() 
     305    { 
     306        return 'LEFT JOIN ' . $this->_parts[0] . '.' . $this->_parts[1] . ' ' 
     307        . $this->_parts[2] . (isset($this->_parts[3]) ? ' ' . $this->_parts[3] : null); 
     308    } 
     309 
     310    private function _innerJoinExpr() 
     311    { 
     312        return 'INNER JOIN ' . $this->_parts[0] . '.' . $this->_parts[1] . ' ' 
     313        . $this->_parts[2] . (isset($this->_parts[3]) ? ' ' . $this->_parts[3] : null); 
     314    } 
     315 
    284316    public static function avg($x) 
    285317    { 
     
    481513        return new self('trim', array($val, $spec, $char)); 
    482514    } 
     515 
     516    public static function on($x) 
     517    { 
     518        return new self('on', array($x)); 
     519    } 
     520 
     521    public static function with($x) 
     522    { 
     523        return new self('with', array($x)); 
     524    } 
     525 
     526    public static function from($from, $alias) 
     527    { 
     528        return new self('from', array($from, $alias)); 
     529    } 
     530 
     531    public static function leftJoin($parentAlias, $join, $alias, $condition = null) 
     532    { 
     533        return new self('leftJoin', array($parentAlias, $join, $alias, $condition)); 
     534    } 
     535 
     536    public static function innerJoin($parentAlias, $join, $alias, $condition = null) 
     537    { 
     538        return new self('innerJoin', array($parentAlias, $join, $alias, $condition)); 
     539    } 
    483540} 
  • trunk/lib/Doctrine/ORM/QueryBuilder.php

    r6030 r6043  
    4747    const STATE_CLEAN = 1; 
    4848 
    49     protected $_entityManager; 
     49    /** 
     50     * @var EntityManager $em Instance of an EntityManager to use for query 
     51     */ 
     52    protected $_em; 
     53 
     54    /** 
     55     * @var array $dqlParts The array of DQL parts collected 
     56     */ 
    5057    protected $_dqlParts = array( 
    5158        'select' => array(), 
     
    5865        'offset' => array() 
    5966    ); 
     67 
     68    /** 
     69     * @var integer $type  The type of query this is. Can be select, update or delete 
     70     */ 
    6071    protected $_type = self::SELECT; 
     72 
     73    /** 
     74     * @var integer $state The state of the query object. Can be dirty or clean. 
     75     */ 
    6176    protected $_state = self::STATE_CLEAN; 
     77 
     78    /** 
     79     * @var string $dql The complete DQL string for this query 
     80     */ 
    6281    protected $_dql; 
    6382 
     83    /** 
     84     * @var array $params Parameters of this query. 
     85     */ 
     86    protected $_params = array(); 
     87 
    6488    public function __construct(EntityManager $entityManager) 
    6589    { 
    66         $this->_entityManager = $entityManager; 
     90        $this->_em = $entityManager; 
    6791    } 
    6892 
     
    7599    { 
    76100        return $this->_type; 
     101    } 
     102 
     103    public function getEntityManager() 
     104    { 
     105        return $this->_em; 
    77106    } 
    78107 
     
    112141    public function getQuery() 
    113142    { 
    114         $q = new Query($this->_entityManager); 
     143        $q = new Query($this->_em); 
    115144        $q->setDql($this->getDql()); 
     145        $q->setParameters($this->getParameters()); 
    116146 
    117147        return $q; 
    118148    } 
    119149 
    120     public function select($select = null) 
    121     { 
     150    public function execute($params = array(), $hydrationMode = null) 
     151    { 
     152        return $this->getQuery()->execute($params, $hydrationMode); 
     153    } 
     154 
     155    /** 
     156     * Sets a query parameter. 
     157     * 
     158     * @param string|integer $key The parameter position or name. 
     159     * @param mixed $value The parameter value. 
     160     */ 
     161    public function setParameter($key, $value) 
     162    { 
     163        $this->_params[$key] = $value; 
     164 
     165        return $this; 
     166    } 
     167     
     168    /** 
     169     * Sets a collection of query parameters. 
     170     * 
     171     * @param array $params 
     172     */ 
     173    public function setParameters(array $params) 
     174    { 
     175        foreach ($params as $key => $value) { 
     176            $this->setParameter($key, $value); 
     177        } 
     178 
     179        return $this; 
     180    } 
     181 
     182    /** 
     183     * Get all defined parameters 
     184     * 
     185     * @return array Defined parameters 
     186     */ 
     187    public function getParameters($params = array()) 
     188    { 
     189        if ($params) { 
     190            return array_merge($this->_params, $params); 
     191        } 
     192        return $this->_params; 
     193    } 
     194     
     195    /** 
     196     * Gets a query parameter. 
     197     *  
     198     * @param mixed $key The key (index or name) of the bound parameter. 
     199     * @return mixed The value of the bound parameter. 
     200     */ 
     201    public function getParameter($key) 
     202    { 
     203        return isset($this->_params[$key]) ? $this->_params[$key] : null; 
     204    } 
     205 
     206    /** 
     207     * Add a single DQL query part to the array of parts 
     208     * 
     209     * @param string $dqlPartName  
     210     * @param string $dqlPart  
     211     * @param string $append  
     212     * @return QueryBuilder $this 
     213     */ 
     214    public function add($dqlPartName, $dqlPart, $append = false) 
     215    { 
     216        if ($append) { 
     217            $this->_dqlParts[$dqlPartName][] = $dqlPart; 
     218        } else { 
     219            $this->_dqlParts[$dqlPartName] = array($dqlPart); 
     220        } 
     221 
     222        $this->_state = self::STATE_DIRTY; 
     223 
     224        return $this; 
     225    } 
     226 
     227    public function select() 
     228    { 
     229        $selects = func_get_args(); 
    122230        $this->_type = self::SELECT; 
    123231 
    124         if ( ! $select) { 
     232        if (empty($selects)) { 
    125233            return $this; 
    126234        } 
    127235 
    128         return $this->_addDqlQueryPart('select', $select, true); 
     236        return $this->add('select', implode(', ', $selects), true); 
    129237    } 
    130238 
     
    137245        } 
    138246 
    139         return $this->_addDqlQueryPart('from', $delete . ' ' . $alias); 
     247        return $this->add('from', Expr::from($delete, $alias)); 
    140248    } 
    141249 
     
    148256        } 
    149257 
    150         return $this->_addDqlQueryPart('from', $update . ' ' . $alias); 
    151     } 
    152  
    153     public function set($key, $value = null) 
    154     { 
    155         return $this->_addDqlQueryPart('set', $key . ' = ' . $value, true); 
     258        return $this->add('from', Expr::from($update, $alias)); 
     259    } 
     260 
     261    public function set($key, $value) 
     262    { 
     263        return $this->add('set', Expr::eq($key, $value), true); 
    156264    } 
    157265 
    158266    public function from($from, $alias) 
    159267    { 
    160         return $this->_addDqlQueryPart('from', $from . ' ' . $alias, true); 
    161     } 
    162  
    163     public function join($join, $alias) 
    164     { 
    165         return $this->_addDqlQueryPart('from', 'INNER JOIN ' . $join . ' ' . $alias, true); 
    166     } 
    167  
    168     public function innerJoin($join, $alias) 
    169     { 
    170         return $this->join($join, $alias); 
    171     } 
    172  
    173     public function leftJoin($join, $alias) 
    174     { 
    175         return $this->_addDqlQueryPart('from', 'LEFT JOIN ' . $join . ' ' . $alias, true); 
     268        return $this->add('from', Expr::from($from, $alias), true); 
     269    } 
     270 
     271    public function innerJoin($parentAlias, $join, $alias, $condition = null) 
     272    { 
     273        return $this->add('from', Expr::innerJoin($parentAlias, $join, $alias, $condition), true); 
     274    } 
     275 
     276    public function leftJoin($parentAlias, $join, $alias, $condition = null) 
     277    { 
     278        return $this->add('from', Expr::leftJoin($parentAlias, $join, $alias, $condition), true); 
    176279    } 
    177280 
    178281    public function where($where) 
    179282    { 
    180         return $this->_addDqlQueryPart('where', $where, false); 
    181     } 
    182  
    183     public function andWhere($where) 
    184     { 
    185         if (count($this->getDqlQueryPart('where')) > 0) { 
    186             $this->_addDqlQueryPart('where', 'AND', true); 
    187         } 
    188  
    189         return $this->_addDqlQueryPart('where', $where, true); 
    190     } 
    191  
    192     public function orWhere($where) 
    193     { 
    194         if (count($this->getDqlQueryPart('where')) > 0) { 
    195             $this->_addDqlQueryPart('where', 'OR', true); 
    196         } 
    197  
    198         return $this->_addDqlQueryPart('where', $where, true); 
     283        return $this->add('where', $where, false); 
    199284    } 
    200285 
    201286    public function groupBy($groupBy) 
    202287    { 
    203         return $this->_addDqlQueryPart('groupBy', $groupBy, false); 
     288        return $this->add('groupBy', $groupBy, false); 
    204289    } 
    205290 
    206291    public function having($having) 
    207292    { 
    208         return $this->_addDqlQueryPart('having', $having, false); 
     293        return $this->add('having', $having, false); 
    209294    } 
    210295 
    211296    public function andHaving($having) 
    212297    { 
    213         if (count($this->getDqlQueryPart('having')) > 0) { 
    214             $this->_addDqlQueryPart('having', 'AND', true); 
    215         } 
    216  
    217         return $this->_addDqlQueryPart('having', $having, true); 
     298        if (count($this->_getDqlQueryPart('having')) > 0) { 
     299            $this->add('having', 'AND', true); 
     300        } 
     301 
     302        return $this->add('having', $having, true); 
    218303    } 
    219304 
    220305    public function orHaving($having) 
    221306    { 
    222         if (count($this->getDqlQueryPart('having')) > 0) { 
    223             $this->_addDqlQueryPart('having', 'OR', true); 
    224         } 
    225  
    226         return $this->_addDqlQueryPart('having', $having, true); 
     307        if (count($this->_getDqlQueryPart('having')) > 0) { 
     308            $this->add('having', 'OR', true); 
     309        } 
     310 
     311        return $this->add('having', $having, true); 
    227312    } 
    228313 
    229314    public function orderBy($sort, $order) 
    230315    { 
    231         return $this->_addDqlQueryPart('orderBy', $sort . ' ' . $order, false); 
     316        return $this->add('orderBy', $sort . ' ' . $order, false); 
    232317    } 
    233318 
    234319    public function addOrderBy($sort, $order) 
    235320    { 
    236         return $this->_addDqlQueryPart('orderBy', $sort . ' ' . $order, true); 
     321        return $this->add('orderBy', $sort . ' ' . $order, true); 
    237322    } 
    238323 
    239324    public function limit($limit) 
    240325    { 
    241         return $this->_addDqlQueryPart('limit', $limit); 
     326        return $this->add('limit', $limit); 
    242327    } 
    243328 
    244329    public function offset($offset) 
    245330    { 
    246         return $this->_addDqlQueryPart('offset', $offset); 
     331        return $this->add('offset', $offset); 
    247332    } 
    248333 
     
    333418 
    334419        $str  = (isset($options['pre']) ? $options['pre'] : ''); 
    335         $str .= implode($options['separator'], $this->getDqlQueryPart($queryPartName)); 
     420        $str .= implode($options['separator'], $this->_getDqlQueryPart($queryPartName)); 
    336421        $str .= (isset($options['post']) ? $options['post'] : ''); 
    337422 
     
    339424    } 
    340425 
    341     private function getDqlQueryPart($queryPartName) 
     426    private function _getDqlQueryPart($queryPartName) 
    342427    { 
    343428        return $this->_dqlParts[$queryPartName]; 
    344429    } 
    345430 
    346     private function _addDqlQueryPart($queryPartName, $queryPart, $append = false) 
    347     { 
    348         if ($append) { 
    349             $this->_dqlParts[$queryPartName][] = $queryPart; 
    350         } else { 
    351             $this->_dqlParts[$queryPartName] = array($queryPart); 
    352         } 
    353  
    354         $this->_state = self::STATE_DIRTY; 
    355         return $this; 
     431    /** 
     432     * Proxy method calls to the Expr class to ease the syntax of the query builder  
     433     * 
     434     * @param string $method     The method name called 
     435     * @param string $arguments  The arguments passed to the method 
     436     * @return void 
     437     * @throws \Doctrine\Common\DoctrineException Throws exception if method could not be proxied 
     438     */ 
     439    public function __call($method, $arguments) 
     440    { 
     441        $class = 'Doctrine\ORM\Query\Expr'; 
     442        if (method_exists($class, $method)) { 
     443            return call_user_func_array(array('Doctrine\ORM\Query\Expr', $method), $arguments); 
     444        } 
     445        throw \Doctrine\Common\DoctrineException::notImplemented($method, get_class($this)); 
    356446    } 
    357447} 
  • trunk/tests/Doctrine/Tests/ORM/Query/ExprTest.php

    r6030 r6043  
    229229        $this->assertEquals('u.id IN(1, 2, 3)', (string) Expr::in('u.id', array(1, 2, 3))); 
    230230    } 
     231 
     232    public function testOnExpr() 
     233    { 
     234        $this->assertEquals('ON 1 = 1', (string) Expr::on(Expr::eq(1, 1))); 
     235    } 
     236 
     237    public function testWithExpr() 
     238    { 
     239        $this->assertEquals('WITH 1 = 1', (string) Expr::with(Expr::eq(1, 1))); 
     240    } 
     241 
     242    public function testLeftJoinExpr() 
     243    { 
     244        $this->assertEquals('LEFT JOIN u.Profile p', (string) Expr::leftJoin('u', 'Profile', 'p')); 
     245    } 
     246 
     247    public function testLeftJoinOnConditionExpr() 
     248    { 
     249        $this->assertEquals('LEFT JOIN u.Profile p ON p.user_id = u.id', (string) Expr::leftJoin('u', 'Profile', 'p', Expr::on(Expr::eq('p.user_id', 'u.id')))); 
     250    } 
     251 
     252    public function testLeftJoinWithConditionExpr() 
     253    { 
     254        $this->assertEquals('LEFT JOIN u.Profile p WITH p.user_id = u.id', (string) Expr::leftJoin('u', 'Profile', 'p', Expr::with(Expr::eq('p.user_id', 'u.id')))); 
     255    } 
     256 
     257    public function testInnerJoinExpr() 
     258    { 
     259        $this->assertEquals('INNER JOIN u.Profile p', (string) Expr::innerJoin('u', 'Profile', 'p')); 
     260    } 
     261 
     262    public function testInnerJoinOnConditionExpr() 
     263    { 
     264        $this->assertEquals('INNER JOIN u.Profile p ON p.user_id = u.id', (string) Expr::innerJoin('u', 'Profile', 'p', Expr::on(Expr::eq('p.user_id', 'u.id')))); 
     265    } 
     266 
     267    public function testInnerJoinWithConditionExpr() 
     268    { 
     269        $this->assertEquals('INNER JOIN u.Profile p WITH p.user_id = u.id', (string) Expr::innerJoin('u', 'Profile', 'p', Expr::with(Expr::eq('p.user_id', 'u.id')))); 
     270    } 
    231271} 
  • trunk/tests/Doctrine/Tests/ORM/QueryBuilderTest.php

    r6030 r6043  
    6363    } 
    6464 
     65    public function testSelectSetsType() 
     66    { 
     67        $qb = QueryBuilder::create($this->_em) 
     68            ->delete('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
     69            ->select('u.id', 'u.username'); 
     70 
     71        $this->assertEquals($qb->getType(), QueryBuilder::SELECT); 
     72    } 
     73 
     74    public function testDeleteSetsType() 
     75    { 
     76        $qb = QueryBuilder::create($this->_em) 
     77            ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
     78            ->delete(); 
     79 
     80        $this->assertEquals($qb->getType(), QueryBuilder::DELETE); 
     81    } 
     82 
     83    public function testUpdateSetsType() 
     84    { 
     85        $qb = QueryBuilder::create($this->_em) 
     86            ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
     87            ->update(); 
     88 
     89        $this->assertEquals($qb->getType(), QueryBuilder::UPDATE); 
     90    } 
     91 
    6592    public function testSimpleSelect() 
    6693    { 
    6794        $qb = QueryBuilder::create($this->_em) 
    6895            ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
    69             ->select('u.id, u.username'); 
     96            ->select('u.id', 'u.username'); 
    7097 
    7198        $this->assertValidQueryBuilder($qb, 'SELECT u.id, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u'); 
     
    84111        $qb = QueryBuilder::create($this->_em) 
    85112            ->update('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
    86             ->set('u.username', ':username', 'jonwage'); 
     113            ->set('u.username', ':username'); 
    87114 
    88115        $this->assertValidQueryBuilder($qb, 'UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.username = :username'); 
    89116    } 
    90117 
    91     public function testJoin() 
    92     { 
    93         $qb = QueryBuilder::create($this->_em) 
    94             ->select('u, a') 
    95             ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
    96             ->join('u.articles', 'a'); 
     118    public function testInnerJoin() 
     119    { 
     120        $qb = QueryBuilder::create($this->_em) 
     121            ->select('u', 'a') 
     122            ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
     123            ->innerJoin('u', 'articles', 'a'); 
    97124 
    98125        $this->assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a'); 
    99126    } 
    100127 
    101     public function testInnerJoin() 
    102     { 
    103         $qb = QueryBuilder::create($this->_em) 
    104             ->select('u, a') 
    105             ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
    106             ->innerJoin('u.articles', 'a'); 
    107  
    108         $this->assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a'); 
    109     } 
    110  
    111128    public function testLeftJoin() 
    112129    { 
    113130        $qb = QueryBuilder::create($this->_em) 
    114             ->select('u, a') 
    115             ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
    116             ->leftJoin('u.articles', 'a'); 
     131            ->select('u', 'a') 
     132            ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
     133            ->leftJoin('u', 'articles', 'a'); 
    117134 
    118135        $this->assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a'); 
     
    124141            ->select('u') 
    125142            ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
    126             ->where('u.id = :uid') 
    127             ->where('u.id = :id'); 
    128  
    129         $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :id'); 
    130     } 
    131  
    132     public function testAndWhere() 
    133     { 
    134         $qb = QueryBuilder::create($this->_em) 
    135             ->select('u') 
    136             ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
    137             ->where('u.id = :id') 
    138             ->andWhere('u.username = :username'); 
    139  
    140         $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :id AND u.username = :username'); 
    141     } 
    142  
    143     public function testOrWhere() 
    144     { 
    145         $qb = QueryBuilder::create($this->_em) 
    146             ->select('u') 
    147             ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
    148             ->where('u.id = :id') 
    149             ->orWhere('u.username = :username'); 
    150  
    151         $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :id OR u.username = :username'); 
    152     } 
    153  
    154     /* 
    155     public function testWhereIn() 
    156     { 
    157         $qb = QueryBuilder::create($this->_em) 
    158             ->select('u') 
    159             ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
    160             ->whereIn('u.id', array(1)); 
    161  
    162         $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id IN(1)'); 
    163     } 
    164  
    165     public function testWhereNotIn() 
    166     { 
    167         $qb = QueryBuilder::create($this->_em) 
    168             ->select('u') 
    169             ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
    170             ->whereNotIn('u.id', array(1)); 
    171  
    172         $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id NOT IN(1)'); 
    173     } 
    174  
    175     public function testAndWhereIn() 
    176     { 
    177         $qb = QueryBuilder::create($this->_em) 
    178             ->select('u') 
    179             ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
    180             ->where('u.id = :id') 
    181             ->andWhereIn('u.id', array(1, 2, 3)); 
    182  
    183         $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :id AND u.id IN(1, 2, 3)'); 
    184     } 
    185  
    186     public function testAndWhereNotIn() 
    187     { 
    188         $qb = QueryBuilder::create($this->_em) 
    189             ->select('u') 
    190             ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
    191             ->where('u.id = :id') 
    192             ->andWhereNotIn('u.id', array(1, 2, 3)); 
    193  
    194         $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :id AND u.id NOT IN(1, 2, 3)'); 
    195     } 
    196  
    197     public function testOrWhereIn() 
    198     { 
    199         $qb = QueryBuilder::create($this->_em) 
    200             ->select('u') 
    201             ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
    202             ->where('u.id = :id') 
    203             ->orWhereIn('u.id', array(1, 2, 3)); 
    204  
    205         $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :id OR u.id IN(1, 2, 3)'); 
    206     } 
    207  
    208     public function testOrWhereNotIn() 
    209     { 
    210         $qb = QueryBuilder::create($this->_em) 
    211             ->select('u') 
    212             ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
    213             ->where('u.id = :id') 
    214             ->orWhereNotIn('u.id', array(1, 2, 3)); 
    215  
    216         $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :id OR u.id NOT IN(1, 2, 3)'); 
    217     } 
    218     */ 
     143            ->where('u.id = :uid'); 
     144 
     145        $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid'); 
     146    } 
    219147 
    220148    public function testGroupBy() 
     
    285213    } 
    286214 
     215    public function testGetQuery() 
     216    { 
     217        $qb = QueryBuilder::create($this->_em) 
     218            ->select('u') 
     219            ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); 
     220        $q = $qb->getQuery(); 
     221 
     222        $this->assertEquals(get_class($q), 'Doctrine\ORM\Query'); 
     223    } 
     224 
     225    public function testSetParameter() 
     226    { 
     227        $qb = QueryBuilder::create($this->_em) 
     228            ->select('u') 
     229            ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
     230            ->where('u.id = :id') 
     231            ->setParameter('id', 1); 
     232 
     233        $q = $qb->getQuery(); 
     234 
     235        $this->assertEquals($q->getParameters(), array('id' => 1)); 
     236    } 
     237 
     238    public function testSetParameters() 
     239    { 
     240        $qb = QueryBuilder::create($this->_em) 
     241            ->select('u') 
     242            ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') 
     243            ->where('u.username = :username OR u.username = :username2'); 
     244 
     245        $qb->setParameters(array('username' => 'jwage', 'username2' => 'jonwage')); 
     246 
     247        $q = $qb->getQuery(); 
     248 
     249        $this->assertEquals($q->getParameters(), array('username' => 'jwage', 'username2' => 'jonwage')); 
     250    } 
     251 
     252    public function testExprProxyWithMagicCall() 
     253    { 
     254        $qb = QueryBuilder::create($this->_em) 
     255            ->select('u') 
     256            ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); 
     257        $qb->where($qb->eq('u.id', 1)); 
     258 
     259        $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = 1'); 
     260    } 
     261 
     262    /** 
     263     * @expectedException \Doctrine\Common\DoctrineException 
     264     */ 
     265    public function testInvalidQueryBuilderMethodThrowsException() 
     266    { 
     267        $qb = QueryBuilder::create($this->_em) 
     268            ->select('u') 
     269            ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); 
     270        $qb->where($qb->blah('u.id', 1)); 
     271    } 
     272 
    287273    public function testLimit() 
    288274    {