public function testAssemble() { $predicate = new NotBetweenPredicate(); $predicate->setField('field'); $this->assertEquals('field NOT BETWEEN NULL AND NULL', QueryAssembler::stringify($predicate)); $predicate->setValues((new NumericExpression())->setValue(1), (new NumericExpression())->setValue(5)); $this->assertEquals('field NOT BETWEEN 1 AND 5', QueryAssembler::stringify($predicate)); $predicate->setValues((new NumericExpression())->setValue('1'), (new NumericExpression())->setValue('5')); $this->assertEquals('field NOT BETWEEN 1 AND 5', QueryAssembler::stringify($predicate)); $predicate->setValues((new StringExpression())->setValue('abc'), (new StringExpression())->setValue('def')); $this->assertEquals('field NOT BETWEEN "abc" AND "def"', QueryAssembler::stringify($predicate)); $predicate = NotBetweenPredicate::create('field', 123, 456); $this->assertEquals('field NOT BETWEEN 123 AND 456', QueryAssembler::stringify($predicate)); $predicate = NotBetweenPredicate::create('field', 'abc', 'def'); $this->assertEquals('field NOT BETWEEN "abc" AND "def"', QueryAssembler::stringify($predicate)); }
public function testBetween() { $predicate = new NotBetweenPredicate(); $predicate->setField('field'); $predicate->setValues((new NumericExpression())->setValue(1), (new NumericExpression())->setValue(5)); $this->assertEquals('"field" <= 1 AND "field" >= 5', CqlAssembler::stringify($predicate)); $predicate = new BetweenPredicate(); $predicate->setField('field'); $this->assertEquals('"field" >= NULL AND "field" <= NULL', CqlAssembler::stringify($predicate)); $predicate->setValues((new NumericExpression())->setValue(1), (new NumericExpression())->setValue(5)); $this->assertEquals('"field" >= 1 AND "field" <= 5', CqlAssembler::stringify($predicate)); $predicate->setValues((new NumericExpression())->setValue('1'), (new NumericExpression())->setValue('5')); $this->assertEquals('"field" >= 1 AND "field" <= 5', CqlAssembler::stringify($predicate)); $predicate->setValues((new StringExpression())->setValue('abc'), (new StringExpression())->setValue('def')); $this->assertEquals('"field" >= \'abc\' AND "field" <= \'def\'', CqlAssembler::stringify($predicate)); $set = new PredicateSet(); $set->addPredicate($predicate); $set->addPredicate(BetweenPredicate::create('field2', 123, 456)); $this->assertEquals('"field" >= \'abc\' AND "field" <= \'def\' AND "field2" >= 123 AND "field2" <= 456', CqlAssembler::stringify($set)); }