ExpressionBuilderTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace Doctrine\Tests\Common\Collections;
  3. use Doctrine\Common\Collections\ExpressionBuilder;
  4. use Doctrine\Common\Collections\Expr\Comparison;
  5. use Doctrine\Common\Collections\Expr\CompositeExpression;
  6. /**
  7. * @group DDC-1637
  8. */
  9. class ExpressionBuilderTest extends \PHPUnit_Framework_TestCase
  10. {
  11. private $builder;
  12. public function setUp()
  13. {
  14. $this->builder = new ExpressionBuilder();
  15. }
  16. public function testAndX()
  17. {
  18. $expr = $this->builder->andX($this->builder->eq("a", "b"));
  19. $this->assertInstanceOf("Doctrine\Common\Collections\Expr\CompositeExpression", $expr);
  20. $this->assertEquals(CompositeExpression::TYPE_AND, $expr->getType());
  21. }
  22. public function testOrX()
  23. {
  24. $expr = $this->builder->orX($this->builder->eq("a", "b"));
  25. $this->assertInstanceOf("Doctrine\Common\Collections\Expr\CompositeExpression", $expr);
  26. $this->assertEquals(CompositeExpression::TYPE_OR, $expr->getType());
  27. }
  28. public function testInvalidAndXArgument()
  29. {
  30. $this->setExpectedException("RuntimeException");
  31. $this->builder->andX("foo");
  32. }
  33. public function testEq()
  34. {
  35. $expr = $this->builder->eq("a", "b");
  36. $this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
  37. $this->assertEquals(Comparison::EQ, $expr->getOperator());
  38. }
  39. public function testNeq()
  40. {
  41. $expr = $this->builder->neq("a", "b");
  42. $this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
  43. $this->assertEquals(Comparison::NEQ, $expr->getOperator());
  44. }
  45. public function testLt()
  46. {
  47. $expr = $this->builder->lt("a", "b");
  48. $this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
  49. $this->assertEquals(Comparison::LT, $expr->getOperator());
  50. }
  51. public function testGt()
  52. {
  53. $expr = $this->builder->gt("a", "b");
  54. $this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
  55. $this->assertEquals(Comparison::GT, $expr->getOperator());
  56. }
  57. public function testGte()
  58. {
  59. $expr = $this->builder->gte("a", "b");
  60. $this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
  61. $this->assertEquals(Comparison::GTE, $expr->getOperator());
  62. }
  63. public function testLte()
  64. {
  65. $expr = $this->builder->lte("a", "b");
  66. $this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
  67. $this->assertEquals(Comparison::LTE, $expr->getOperator());
  68. }
  69. public function testIn()
  70. {
  71. $expr = $this->builder->in("a", array("b"));
  72. $this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
  73. $this->assertEquals(Comparison::IN, $expr->getOperator());
  74. }
  75. public function testNotIn()
  76. {
  77. $expr = $this->builder->notIn("a", array("b"));
  78. $this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
  79. $this->assertEquals(Comparison::NIN, $expr->getOperator());
  80. }
  81. public function testIsNull()
  82. {
  83. $expr = $this->builder->isNull("a");
  84. $this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
  85. $this->assertEquals(Comparison::EQ, $expr->getOperator());
  86. }
  87. public function testContains()
  88. {
  89. $expr = $this->builder->contains("a", "b");
  90. $this->assertInstanceOf("Doctrine\Common\Collections\Expr\Comparison", $expr);
  91. $this->assertEquals(Comparison::CONTAINS, $expr->getOperator());
  92. }
  93. }