/**
  * @test
  */
 public function shouldUseBothAndOrOperator()
 {
     // given
     $query = new Query();
     $query->table = 'products';
     $query->where(array('a' => '5'));
     $query->where(Any::of(array('name' => 'bob', 'id' => '1')));
     // when
     $sql = $this->dialect->buildQuery($query);
     // then
     $this->assertEquals('SELECT * FROM products WHERE a = ? AND (name = ? OR id = ?)', $sql);
 }
 /**
  * @test
  */
 public function shouldSearchAnyOfAndWhereValues()
 {
     //given
     $category = Category::create(array('name' => 'shop'));
     $product1 = Product::create(array('name' => 'notebook', 'description' => 'notebook desc', 'id_category' => $category->getId()));
     $product2 = Product::create(array('name' => 'tablet', 'description' => 'tablet desc', 'id_category' => $category->getId()));
     Product::create(array('name' => 'pc', 'description' => 'pc desc'));
     //when
     $products = Product::where(Any::of(array('name' => 'tablet', 'description' => Restrictions::like('%desc'))))->where(array('id_category' => $category->getId()))->fetchAll();
     //then
     Assert::thatArray($products)->hasSize(2)->onProperty('id')->containsExactly($product1->getId(), $product2->getId());
 }
Exemple #3
0
 /**
  * @test
  */
 public function shouldJoinConditionsWithOrForAnyOfAndWhereClauses()
 {
     // when
     $result = Any::of(array(WhereClause::create('a = 1'), WhereClause::create('a = 2')));
     // then
     $this->assertEquals('(a = 1 OR a = 2)', $result->toSql());
 }