/** * @test */ public function itShouldAllowWhereOrConditions() { $this->query->setTable('user')->where('OR')->equals('user_id', 1)->like('name', '%N%'); $this->assertSame('OR', $this->query->getWhereOperator()); $expected = 'SELECT user.* FROM user WHERE (user.user_id = :v1) OR (user.name LIKE :v2)'; $this->assertSame($expected, $this->writer->write($this->query)); $expected = array(':v1' => 1, ':v2' => '%N%'); $this->assertEquals($expected, $this->writer->getValues()); }
/** * @param Select $select * @param array $parts * * @return $this */ public function writeSelectWhere(Select $select, array &$parts) { $str = ''; $wheres = $this->writeSelectWheres($select->getAllWheres()); $wheres = \array_filter($wheres); if (\count($wheres) > 0) { $str = 'WHERE '; $separator = ' ' . $this->writer->writeConjunction($select->getWhereOperator()) . ' '; $str .= \implode($separator, $wheres); } $parts = \array_merge($parts, [$str]); return $this; }
/** * @param Select $select * @param array $parts * * @return $this */ public function writeSelectWhere(Select $select, array &$parts) { $str = ""; $wheres = $this->writeSelectWheres($select->getAllWheres()); $wheres = array_filter($wheres); if (count($wheres) > 0) { $str = "WHERE "; $separator = " " . $this->writer->writeConjunction($select->getWhereOperator()) . " "; $str .= implode($separator, $wheres); } $parts = array_merge($parts, array($str)); return $this; }