2 namespace Doctrine\Tests\Common\Collections;
4 use Doctrine\Common\Collections\Criteria;
5 use Doctrine\Common\Collections\Expr\Comparison;
6 use Doctrine\Common\Collections\Expr\CompositeExpression;
8 class CriteriaTest extends \PHPUnit_Framework_TestCase
10 public function testCreate()
12 $criteria = Criteria::create();
14 $this->assertInstanceOf("Doctrine\Common\Collections\Criteria", $criteria);
17 public function testConstructor()
19 $expr = new Comparison("field", "=", "value");
20 $criteria = new Criteria($expr, array("foo" => "ASC"), 10, 20);
22 $this->assertSame($expr, $criteria->getWhereExpression());
23 $this->assertEquals(array("foo" => "ASC"), $criteria->getOrderings());
24 $this->assertEquals(10, $criteria->getFirstResult());
25 $this->assertEquals(20, $criteria->getMaxResults());
28 public function testWhere()
30 $expr = new Comparison("field", "=", "value");
31 $criteria = new Criteria();
33 $criteria->where($expr);
35 $this->assertSame($expr, $criteria->getWhereExpression());
38 public function testAndWhere()
40 $expr = new Comparison("field", "=", "value");
41 $criteria = new Criteria();
43 $criteria->where($expr);
44 $expr = $criteria->getWhereExpression();
45 $criteria->andWhere($expr);
47 $where = $criteria->getWhereExpression();
48 $this->assertInstanceOf('Doctrine\Common\Collections\Expr\CompositeExpression', $where);
50 $this->assertEquals(CompositeExpression::TYPE_AND, $where->getType());
51 $this->assertSame(array($expr, $expr), $where->getExpressionList());
54 public function testOrWhere()
56 $expr = new Comparison("field", "=", "value");
57 $criteria = new Criteria();
59 $criteria->where($expr);
60 $expr = $criteria->getWhereExpression();
61 $criteria->orWhere($expr);
63 $where = $criteria->getWhereExpression();
64 $this->assertInstanceOf('Doctrine\Common\Collections\Expr\CompositeExpression', $where);
66 $this->assertEquals(CompositeExpression::TYPE_OR, $where->getType());
67 $this->assertSame(array($expr, $expr), $where->getExpressionList());
70 public function testOrderings()
72 $criteria = Criteria::create()
73 ->orderBy(array("foo" => "ASC"));
75 $this->assertEquals(array("foo" => "ASC"), $criteria->getOrderings());
78 public function testExpr()
80 $this->assertInstanceOf('Doctrine\Common\Collections\ExpressionBuilder', Criteria::expr());