Skip to content

Commit ab94832

Browse files
MohannadNajtpetry
andauthored
chore: tests: use schema builder for columns setup (tpetry#20)
Co-authored-by: tpetry <[email protected]>
1 parent b95836f commit ab94832

38 files changed

+352
-95
lines changed

tests/Function/Aggregate/AvgTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
declare(strict_types=1);
44

55
use Illuminate\Database\Query\Expression;
6+
use Illuminate\Database\Schema\Blueprint;
67
use Tpetry\QueryExpressions\Function\Aggregate\Avg;
78

89
it('can aggregate a column by AVG')
910
->expect(new Avg('val'))
10-
->toBeExecutable(['val int'])
11+
->toBeExecutable(function (Blueprint $table) {
12+
$table->integer('val');
13+
})
1114
->toBeMysql('avg(`val`)')
1215
->toBePgsql('avg("val")')
1316
->toBeSqlite('avg("val")')

tests/Function/Aggregate/CountFilterTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
declare(strict_types=1);
44

55
use Illuminate\Database\Query\Expression;
6+
use Illuminate\Database\Schema\Blueprint;
67
use Tpetry\QueryExpressions\Function\Aggregate\CountFilter;
78

89
it('can aggregate a column by COUNT with a filter')
910
->expect(new CountFilter(new Expression('val = 1')))
10-
->toBeExecutable(['val int'])
11+
->toBeExecutable(function (Blueprint $table) {
12+
$table->integer('val');
13+
})
1114
->toBeMysql('sum(val = 1)')
1215
->toBePgsql('count(*) filter (where val = 1)')
1316
->toBeSqlite('count(*) filter (where val = 1)')

tests/Function/Aggregate/CountTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@
33
declare(strict_types=1);
44

55
use Illuminate\Database\Query\Expression;
6+
use Illuminate\Database\Schema\Blueprint;
67
use Tpetry\QueryExpressions\Function\Aggregate\Count;
78

89
it('can aggregate a column by COUNT')
910
->expect(new Count('val'))
10-
->toBeExecutable(['val int'])
11+
->toBeExecutable(function (Blueprint $table) {
12+
$table->integer('val');
13+
})
1114
->toBeMysql('count(`val`)')
1215
->toBePgsql('count("val")')
1316
->toBeSqlite('count("val")')
1417
->toBeSqlsrv('count([val])');
1518

1619
it('can aggregate a column by COUNT with DISTINCT')
1720
->expect(new Count('val', true))
18-
->toBeExecutable(['val int'])
21+
->toBeExecutable(function (Blueprint $table) {
22+
$table->integer('val');
23+
})
1924
->toBeMysql('count(distinct `val`)')
2025
->toBePgsql('count(distinct "val")')
2126
->toBeSqlite('count(distinct "val")')

tests/Function/Aggregate/MaxTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
declare(strict_types=1);
44

55
use Illuminate\Database\Query\Expression;
6+
use Illuminate\Database\Schema\Blueprint;
67
use Tpetry\QueryExpressions\Function\Aggregate\Max;
78

89
it('can aggregate a column by MAX')
910
->expect(new Max('val'))
10-
->toBeExecutable(['val int'])
11+
->toBeExecutable(function (Blueprint $table) {
12+
$table->integer('val');
13+
})
1114
->toBeMysql('max(`val`)')
1215
->toBePgsql('max("val")')
1316
->toBeSqlite('max("val")')

tests/Function/Aggregate/MinTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
declare(strict_types=1);
44

55
use Illuminate\Database\Query\Expression;
6+
use Illuminate\Database\Schema\Blueprint;
67
use Tpetry\QueryExpressions\Function\Aggregate\Min;
78

89
it('can aggregate a column by MIN')
910
->expect(new Min('val'))
10-
->toBeExecutable(['val int'])
11+
->toBeExecutable(function (Blueprint $table) {
12+
$table->integer('val');
13+
})
1114
->toBeMysql('min(`val`)')
1215
->toBePgsql('min("val")')
1316
->toBeSqlite('min("val")')

tests/Function/Aggregate/SumFilterTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@
33
declare(strict_types=1);
44

55
use Illuminate\Database\Query\Expression;
6+
use Illuminate\Database\Schema\Blueprint;
67
use Tpetry\QueryExpressions\Function\Aggregate\SumFilter;
78

89
it('can aggregate a column by SUM with a filter')
910
->expect(new SumFilter('val1', new Expression('val2 = 1')))
10-
->toBeExecutable(['val1 int', 'val2 int'])
11+
->toBeExecutable(function (Blueprint $table) {
12+
$table->integer('val1');
13+
$table->integer('val2');
14+
})
1115
->toBeMysql('sum(case when val2 = 1 then `val1` else 0 end)')
1216
->toBePgsql('sum("val1") filter (where val2 = 1)')
1317
->toBeSqlite('sum("val1") filter (where val2 = 1)')
1418
->toBeSqlsrv('sum(case when val2 = 1 then [val1] else 0 end)');
1519

1620
it('can aggregate an expression by SUM with a filter')
1721
->expect(new SumFilter(new Expression(1), new Expression('val = 1')))
18-
->toBeExecutable(['val int'])
22+
->toBeExecutable(function (Blueprint $table) {
23+
$table->integer('val');
24+
})
1925
->toBeMysql('sum(case when val = 1 then 1 else 0 end)')
2026
->toBePgsql('sum(1) filter (where val = 1)')
2127
->toBeSqlite('sum(1) filter (where val = 1)')

tests/Function/Aggregate/SumTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
declare(strict_types=1);
44

55
use Illuminate\Database\Query\Expression;
6+
use Illuminate\Database\Schema\Blueprint;
67
use Tpetry\QueryExpressions\Function\Aggregate\Sum;
78

89
it('can aggregate a column by SUM')
910
->expect(new Sum('val'))
10-
->toBeExecutable(['val int'])
11+
->toBeExecutable(function (Blueprint $table) {
12+
$table->integer('val');
13+
})
1114
->toBeMysql('sum(`val`)')
1215
->toBePgsql('sum("val")')
1316
->toBeSqlite('sum("val")')

tests/Function/Comparison/StrListContainsTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
declare(strict_types=1);
44

55
use Illuminate\Database\Query\Expression;
6+
use Illuminate\Database\Schema\Blueprint;
67
use Tpetry\QueryExpressions\Function\Comparison\StrListContains;
78

89
it('can check for existence of a column within a column string list')
910
->expect(new StrListContains('haystack', 'needle'))
10-
->toBeExecutable(['haystack varchar(255)', 'needle varchar(255)'], options: [
11+
->toBeExecutable(function (Blueprint $table) {
12+
$table->string('haystack');
13+
$table->string('needle');
14+
}, options: [
1115
'sqlsrv' => ['position' => 'where'],
1216
])
1317
->toBeMysql('FIND_IN_SET(`needle`, `haystack`) > 0')
@@ -27,7 +31,9 @@
2731

2832
it('can check for existence of a column within an expression string list')
2933
->expect(new StrListContains(new Expression("'a,b,c'"), 'needle'))
30-
->toBeExecutable(['needle varchar(255)'], options: [
34+
->toBeExecutable(function (Blueprint $table) {
35+
$table->string('needle');
36+
}, options: [
3137
'sqlsrv' => ['position' => 'where'],
3238
])
3339
->toBeMysql("FIND_IN_SET(`needle`, 'a,b,c') > 0")
@@ -37,7 +43,9 @@
3743

3844
it('can check for existence of an expression within a column string list')
3945
->expect(new StrListContains('haystack', new Expression("'a'")))
40-
->toBeExecutable(['haystack varchar(255)'], options: [
46+
->toBeExecutable(function (Blueprint $table) {
47+
$table->string('haystack');
48+
}, options: [
4149
'sqlsrv' => ['position' => 'where'],
4250
])
4351
->toBeMysql("FIND_IN_SET('a', `haystack`) > 0")

tests/Function/Conditional/CoalesceTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
declare(strict_types=1);
44

55
use Illuminate\Database\Query\Expression;
6+
use Illuminate\Database\Schema\Blueprint;
67
use Tpetry\QueryExpressions\Function\Conditional\Coalesce;
78

89
it('can combine multiple columns')
910
->expect(new Coalesce(['val1', 'val2', 'val3']))
10-
->toBeExecutable(['val1 int', 'val2 int', 'val3 int'])
11+
->toBeExecutable(function (Blueprint $table) {
12+
$table->integer('val1');
13+
$table->integer('val2');
14+
$table->integer('val3');
15+
})
1116
->toBeMysql('coalesce(`val1`, `val2`, `val3`)')
1217
->toBePgsql('coalesce("val1", "val2", "val3")')
1318
->toBeSqlite('coalesce("val1", "val2", "val3")')
@@ -23,7 +28,10 @@
2328

2429
it('can combine multiple columns and expressions')
2530
->expect(new Coalesce(['val1', 'val2', new Expression(3)]))
26-
->toBeExecutable(['val1 int', 'val2 int'])
31+
->toBeExecutable(function (Blueprint $table) {
32+
$table->integer('val1');
33+
$table->integer('val2');
34+
})
2735
->toBeMysql('coalesce(`val1`, `val2`, 3)')
2836
->toBePgsql('coalesce("val1", "val2", 3)')
2937
->toBeSqlite('coalesce("val1", "val2", 3)')

tests/Function/Conditional/GreatestTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
declare(strict_types=1);
44

55
use Illuminate\Database\Query\Expression;
6+
use Illuminate\Database\Schema\Blueprint;
67
use Tpetry\QueryExpressions\Function\Conditional\Greatest;
78

89
it('can combine multiple columns')
910
->expect(new Greatest(['val1', 'val2', 'val3']))
10-
->toBeExecutable(['val1 int', 'val2 int', 'val3 int'])
11+
->toBeExecutable(function (Blueprint $table) {
12+
$table->integer('val1');
13+
$table->integer('val2');
14+
$table->integer('val3');
15+
})
1116
->toBeMysql('greatest(`val1`, `val2`, `val3`)')
1217
->toBePgsql('greatest("val1", "val2", "val3")')
1318
->toBeSqlite('max("val1", "val2", "val3")')
@@ -23,7 +28,10 @@
2328

2429
it('can combine multiple columns and expressions')
2530
->expect(new Greatest(['val1', 'val2', new Expression(3)]))
26-
->toBeExecutable(['val1 int', 'val2 int'])
31+
->toBeExecutable(function (Blueprint $table) {
32+
$table->integer('val1');
33+
$table->integer('val2');
34+
})
2735
->toBeMysql('greatest(`val1`, `val2`, 3)')
2836
->toBePgsql('greatest("val1", "val2", 3)')
2937
->toBeSqlite('max("val1", "val2", 3)')

0 commit comments

Comments
 (0)