Skip to content

Commit 7d17e41

Browse files
authored
[9.x] Improve test for orWhereBetween ,OrWhereNotBetween in QueryBuilder (#44170)
1 parent 9235af3 commit 7d17e41

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

tests/Database/DatabaseQueryBuilderTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,72 @@ public function testWhereBetweens()
700700
$this->assertEquals([0 => 1, 1 => 2], $builder->getBindings());
701701
}
702702

703+
public function testOrWhereBetween()
704+
{
705+
$builder = $this->getBuilder();
706+
$builder->select('*')->from('users')->where('id', '=', 1)->orWhereBetween('id', [3, 5]);
707+
$this->assertSame('select * from "users" where "id" = ? or "id" between ? and ?', $builder->toSql());
708+
$this->assertEquals([0 => 1, 1 => 3, 2 => 5], $builder->getBindings());
709+
710+
$builder = $this->getBuilder();
711+
$builder->select('*')->from('users')->where('id', '=', 1)->orWhereBetween('id', [[3, 4, 5]]);
712+
$this->assertSame('select * from "users" where "id" = ? or "id" between ? and ?', $builder->toSql());
713+
$this->assertEquals([0 => 1, 1 => 3, 2 => 4], $builder->getBindings());
714+
715+
$builder = $this->getBuilder();
716+
$builder->select('*')->from('users')->where('id', '=', 1)->orWhereBetween('id', [[3, 5]]);
717+
$this->assertSame('select * from "users" where "id" = ? or "id" between ? and ?', $builder->toSql());
718+
$this->assertEquals([0 => 1, 1 => 3, 2 => 5], $builder->getBindings());
719+
720+
$builder = $this->getBuilder();
721+
$builder->select('*')->from('users')->where('id', '=', 1)->orWhereBetween('id', [[4], [6, 8]]);
722+
$this->assertSame('select * from "users" where "id" = ? or "id" between ? and ?', $builder->toSql());
723+
$this->assertEquals([0 => 1, 1 => 4, 2 => 6], $builder->getBindings());
724+
725+
$builder = $this->getBuilder();
726+
$builder->select('*')->from('users')->where('id', '=', 1)->orWhereBetween('id', collect([3, 4]));
727+
$this->assertSame('select * from "users" where "id" = ? or "id" between ? and ?', $builder->toSql());
728+
$this->assertEquals([0 => 1, 1 => 3, 2 => 4], $builder->getBindings());
729+
730+
$builder = $this->getBuilder();
731+
$builder->select('*')->from('users')->where('id', '=', 1)->orWhereBetween('id', [new Raw(3), new Raw(4)]);
732+
$this->assertSame('select * from "users" where "id" = ? or "id" between 3 and 4', $builder->toSql());
733+
$this->assertEquals([0 => 1], $builder->getBindings());
734+
}
735+
736+
public function testOrWhereNotBetween()
737+
{
738+
$builder = $this->getBuilder();
739+
$builder->select('*')->from('users')->where('id', '=', 1)->orWhereNotBetween('id', [3, 5]);
740+
$this->assertSame('select * from "users" where "id" = ? or "id" not between ? and ?', $builder->toSql());
741+
$this->assertEquals([0 => 1, 1 => 3, 2 => 5], $builder->getBindings());
742+
743+
$builder = $this->getBuilder();
744+
$builder->select('*')->from('users')->where('id', '=', 1)->orWhereNotBetween('id', [[3, 4, 5]]);
745+
$this->assertSame('select * from "users" where "id" = ? or "id" not between ? and ?', $builder->toSql());
746+
$this->assertEquals([0 => 1, 1 => 3, 2 => 4], $builder->getBindings());
747+
748+
$builder = $this->getBuilder();
749+
$builder->select('*')->from('users')->where('id', '=', 1)->orWhereNotBetween('id', [[3, 5]]);
750+
$this->assertSame('select * from "users" where "id" = ? or "id" not between ? and ?', $builder->toSql());
751+
$this->assertEquals([0 => 1, 1 => 3, 2 => 5], $builder->getBindings());
752+
753+
$builder = $this->getBuilder();
754+
$builder->select('*')->from('users')->where('id', '=', 1)->orWhereNotBetween('id', [[4], [6, 8]]);
755+
$this->assertSame('select * from "users" where "id" = ? or "id" not between ? and ?', $builder->toSql());
756+
$this->assertEquals([0 => 1, 1 => 4, 2 => 6], $builder->getBindings());
757+
758+
$builder = $this->getBuilder();
759+
$builder->select('*')->from('users')->where('id', '=', 1)->orWhereNotBetween('id', collect([3, 4]));
760+
$this->assertSame('select * from "users" where "id" = ? or "id" not between ? and ?', $builder->toSql());
761+
$this->assertEquals([0 => 1, 1 => 3, 2 => 4], $builder->getBindings());
762+
763+
$builder = $this->getBuilder();
764+
$builder->select('*')->from('users')->where('id', '=', 1)->orWhereNotBetween('id', [new Raw(3), new Raw(4)]);
765+
$this->assertSame('select * from "users" where "id" = ? or "id" not between 3 and 4', $builder->toSql());
766+
$this->assertEquals([0 => 1], $builder->getBindings());
767+
}
768+
703769
public function testWhereBetweenColumns()
704770
{
705771
$builder = $this->getBuilder();

0 commit comments

Comments
 (0)