CriteriaTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Doctrine\Tests\Common\Collections;
  3. use Doctrine\Common\Collections\Criteria;
  4. use Doctrine\Common\Collections\Expr\Comparison;
  5. use Doctrine\Common\Collections\Expr\CompositeExpression;
  6. class CriteriaTest extends \PHPUnit_Framework_TestCase
  7. {
  8. public function testCreate()
  9. {
  10. $criteria = Criteria::create();
  11. $this->assertInstanceOf("Doctrine\Common\Collections\Criteria", $criteria);
  12. }
  13. public function testConstructor()
  14. {
  15. $expr = new Comparison("field", "=", "value");
  16. $criteria = new Criteria($expr, array("foo" => "ASC"), 10, 20);
  17. $this->assertSame($expr, $criteria->getWhereExpression());
  18. $this->assertEquals(array("foo" => "ASC"), $criteria->getOrderings());
  19. $this->assertEquals(10, $criteria->getFirstResult());
  20. $this->assertEquals(20, $criteria->getMaxResults());
  21. }
  22. public function testWhere()
  23. {
  24. $expr = new Comparison("field", "=", "value");
  25. $criteria = new Criteria();
  26. $criteria->where($expr);
  27. $this->assertSame($expr, $criteria->getWhereExpression());
  28. }
  29. public function testAndWhere()
  30. {
  31. $expr = new Comparison("field", "=", "value");
  32. $criteria = new Criteria();
  33. $criteria->where($expr);
  34. $expr = $criteria->getWhereExpression();
  35. $criteria->andWhere($expr);
  36. $where = $criteria->getWhereExpression();
  37. $this->assertInstanceOf('Doctrine\Common\Collections\Expr\CompositeExpression', $where);
  38. $this->assertEquals(CompositeExpression::TYPE_AND, $where->getType());
  39. $this->assertSame(array($expr, $expr), $where->getExpressionList());
  40. }
  41. public function testOrWhere()
  42. {
  43. $expr = new Comparison("field", "=", "value");
  44. $criteria = new Criteria();
  45. $criteria->where($expr);
  46. $expr = $criteria->getWhereExpression();
  47. $criteria->orWhere($expr);
  48. $where = $criteria->getWhereExpression();
  49. $this->assertInstanceOf('Doctrine\Common\Collections\Expr\CompositeExpression', $where);
  50. $this->assertEquals(CompositeExpression::TYPE_OR, $where->getType());
  51. $this->assertSame(array($expr, $expr), $where->getExpressionList());
  52. }
  53. public function testOrderings()
  54. {
  55. $criteria = Criteria::create()
  56. ->orderBy(array("foo" => "ASC"));
  57. $this->assertEquals(array("foo" => "ASC"), $criteria->getOrderings());
  58. }
  59. public function testExpr()
  60. {
  61. $this->assertInstanceOf('Doctrine\Common\Collections\ExpressionBuilder', Criteria::expr());
  62. }
  63. }