public function testAssemble() { $clause = new WhereClause(); $eq = new EqualPredicate(); $eq->setField('one')->setExpression((new StringExpression())->setValue('val')); $clause->addPredicate($eq); $this->assertEquals('WHERE one = "val"', QueryAssembler::stringify($clause)); $eq = new GreaterThanPredicate(); $eq->setField('two')->setExpression((new NumericExpression())->setValue(5)); $clause->addPredicate($eq); $this->assertEquals('WHERE one = "val" AND two > 5', QueryAssembler::stringify($clause)); }
public function testAssemble() { $predicate = new GreaterThanPredicate(); $predicate->setField('field'); $this->assertEquals('field > NULL', QueryAssembler::stringify($predicate)); $predicate->setExpression((new NumericExpression())->setValue(1)); $this->assertEquals('field > 1', QueryAssembler::stringify($predicate)); $predicate->setExpression((new NumericExpression())->setValue('1')); $this->assertEquals('field > 1', QueryAssembler::stringify($predicate)); $predicate->setExpression((new StringExpression())->setValue('abc')); $this->assertEquals('field > "abc"', QueryAssembler::stringify($predicate)); }
public function testAssemble() { $expression = MatchExpression::create(FieldExpression::createWithTable('field1', 'table1'), StringExpression::create('this is a test search')); $expression->addField(FieldExpression::createWithTable('field2', 'table2')); $this->assertEquals('MATCH (`table1`.`field1`,`table2`.`field2`) AGAINST ("this is a test search")', MySQLAssembler::stringify($expression)); $expression->setSearchModifier(MatchExpression::BOOLEAN_MODE); $this->assertEquals('MATCH (`table1`.`field1`,`table2`.`field2`) AGAINST ("this is a test search" IN BOOLEAN MODE)', MySQLAssembler::stringify($expression)); $expression->setSearchModifier(MatchExpression::WITH_QUERY_EXPANSION); $this->assertEquals('MATCH (`table1`.`field1`,`table2`.`field2`) AGAINST ("this is a test search" WITH QUERY EXPANSION)', MySQLAssembler::stringify($expression)); $expression->setSearchModifier(MatchExpression::BOOLEAN_MODE); $stmt = QueryBuilder::select(AllSelectExpression::create())->from('tbl')->where(GreaterThanPredicate::create($expression, 0))->limit(5); $assembler = new MySQLAssembler($stmt); $this->assertEquals('SELECT * FROM `tbl` WHERE MATCH (`table1`.`field1`,`table2`.`field2`) AGAINST (? IN BOOLEAN MODE) > ? LIMIT ?', $assembler->getQuery()); $this->assertEquals(['this is a test search', 0, 5], $assembler->getParameters()); }