Skip to content

Commit d787dae

Browse files
committed
Tests: add some missing tests
1 parent 7ed6f1d commit d787dae

File tree

2 files changed

+96
-4
lines changed

2 files changed

+96
-4
lines changed

tests/Unit/FluentConditionTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testAdd(): void
7474
}
7575

7676

77-
public function testArrayAcces(): void
77+
public function testArrayAccess(): void
7878
{
7979
$condition = Fluent\Condition::createOr();
8080

@@ -110,6 +110,15 @@ public function testArrayAcces(): void
110110
Tester\Assert::same([['column = ?', 1]], $conditions);
111111
}
112112

113+
114+
public function testArrayAccessBadOffset(): void
115+
{
116+
Tester\Assert::exception(function (): void {
117+
$condition = Fluent\Condition::createOr();
118+
$condition[0] = ['column = ?', 1];
119+
}, \InvalidArgumentException::class, 'Can\'t set non-existing offset \'0\'.');
120+
}
121+
113122
}
114123

115124
(new FluentConditionTest())->run();

tests/Unit/FluentQueryTest.php

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,50 @@ public function testJoinNoOn(): void
561561
}
562562

563563

564+
public function testJoinNonExistingOn(): void
565+
{
566+
Tester\Assert::exception(function (): void {
567+
$this->query()
568+
->select(['x.column'])
569+
->from('table', 't')
570+
->join('another', 'x')
571+
->on('y', 'y.id = t.id')
572+
->toDbQuery();
573+
}, Fluent\Exceptions\QueryBuilderException::class, null, Fluent\Exceptions\QueryBuilderException::NO_CORRESPONDING_TABLE);
574+
}
575+
576+
577+
public function testOtherJoins(): void
578+
{
579+
$queryRightJoin = $this->query()
580+
->select(['t1.column1', 't2.column2'])
581+
->from('table1', 't1')
582+
->rightJoin('table2', 't2', 't2.id = t1.id')
583+
->toDbQuery();
584+
585+
Tester\Assert::same('SELECT t1.column1, t2.column2 FROM table1 AS t1 RIGHT OUTER JOIN table2 AS t2 ON t2.id = t1.id', $queryRightJoin->sql);
586+
Tester\Assert::same([], $queryRightJoin->params);
587+
588+
$queryFullJoin = $this->query()
589+
->select(['t1.column1', 't2.column2'])
590+
->from('table1', 't1')
591+
->fullJoin('table2', 't2', 't2.id = t1.id')
592+
->toDbQuery();
593+
594+
Tester\Assert::same('SELECT t1.column1, t2.column2 FROM table1 AS t1 FULL OUTER JOIN table2 AS t2 ON t2.id = t1.id', $queryFullJoin->sql);
595+
Tester\Assert::same([], $queryFullJoin->params);
596+
597+
$queryCrossJoin = $this->query()
598+
->select(['t1.column1', 't2.column2'])
599+
->from('table1', 't1')
600+
->crossJoin('table2', 't2')
601+
->toDbQuery();
602+
603+
Tester\Assert::same('SELECT t1.column1, t2.column2 FROM table1 AS t1 CROSS JOIN table2 AS t2', $queryCrossJoin->sql);
604+
Tester\Assert::same([], $queryCrossJoin->params);
605+
}
606+
607+
564608
public function testLateralFrom(): void
565609
{
566610
$query = $this->query()
@@ -603,7 +647,7 @@ public function testLateralJoinWithFluentQuery(): void
603647
}
604648

605649

606-
public function testSelectCombine(): void
650+
public function testSelectUnion(): void
607651
{
608652
$query = $this->query()
609653
->from('table', 't')
@@ -616,7 +660,7 @@ public function testSelectCombine(): void
616660
}
617661

618662

619-
public function testSelectCombineFluent(): void
663+
public function testSelectUnionFluent(): void
620664
{
621665
$query = $this->query()
622666
->from('table', 't')
@@ -633,7 +677,7 @@ public function testSelectCombineFluent(): void
633677
}
634678

635679

636-
public function testSelectCombineQuery(): void
680+
public function testSelectUnionQuery(): void
637681
{
638682
$query = $this->query()
639683
->from('table', 't')
@@ -646,6 +690,45 @@ public function testSelectCombineQuery(): void
646690
}
647691

648692

693+
public function testSelectUnionAll(): void
694+
{
695+
$query = $this->query()
696+
->from('table', 't')
697+
->select(['column'])
698+
->unionAll('SELECT column FROM table2 AS t2')
699+
->toDbQuery();
700+
701+
Tester\Assert::same('(SELECT column FROM table AS t) UNION ALL (SELECT column FROM table2 AS t2)', $query->sql);
702+
Tester\Assert::same([], $query->params);
703+
}
704+
705+
706+
public function testSelectIntersect(): void
707+
{
708+
$query = $this->query()
709+
->from('table', 't')
710+
->select(['column'])
711+
->intersect('SELECT column FROM table2 AS t2')
712+
->toDbQuery();
713+
714+
Tester\Assert::same('(SELECT column FROM table AS t) INTERSECT (SELECT column FROM table2 AS t2)', $query->sql);
715+
Tester\Assert::same([], $query->params);
716+
}
717+
718+
719+
public function testSelectExcept(): void
720+
{
721+
$query = $this->query()
722+
->from('table', 't')
723+
->select(['column'])
724+
->except('SELECT column FROM table2 AS t2')
725+
->toDbQuery();
726+
727+
Tester\Assert::same('(SELECT column FROM table AS t) EXCEPT (SELECT column FROM table2 AS t2)', $query->sql);
728+
Tester\Assert::same([], $query->params);
729+
}
730+
731+
649732
public function testSelectNoColumns(): void
650733
{
651734
Tester\Assert::exception(function (): void {

0 commit comments

Comments
 (0)