Skip to content

Commit 6094452

Browse files
committed
(test): Update tests for simplified Builder API
1 parent 78a44c1 commit 6094452

5 files changed

Lines changed: 43 additions & 50 deletions

File tree

tests/Integration/Builder/MySQLIntegrationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public function testSelectWithExistsSubquery(): void
335335
{
336336
$subquery = (new Builder())
337337
->from('orders', 'o')
338-
->selectRaw('1')
338+
->select('1')
339339
->filter([Query::equal('o.status', ['completed'])]);
340340

341341
$result = $this->fresh()
@@ -350,7 +350,7 @@ public function testSelectWithExistsSubquery(): void
350350

351351
$noMatchSubquery = (new Builder())
352352
->from('orders', 'o')
353-
->selectRaw('1')
353+
->select('1')
354354
->filter([Query::equal('o.status', ['refunded'])]);
355355

356356
$emptyResult = $this->fresh()

tests/Query/Builder/ClickHouseTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4557,7 +4557,6 @@ public function testEmptyTableNameWithFinal(): void
45574557
$this->expectException(ValidationException::class);
45584558
$this->expectExceptionMessage('No table specified');
45594559
(new Builder())
4560-
->from('')
45614560
->final()
45624561
->build();
45634562
}
@@ -4567,7 +4566,6 @@ public function testEmptyTableNameWithSample(): void
45674566
$this->expectException(ValidationException::class);
45684567
$this->expectExceptionMessage('No table specified');
45694568
(new Builder())
4570-
->from('')
45714569
->sample(0.5)
45724570
->build();
45734571
}
@@ -7148,7 +7146,7 @@ public function testWhereNotInSubqueryClickHouse(): void
71487146

71497147
public function testSelectSubClickHouse(): void
71507148
{
7151-
$sub = (new Builder())->from('events')->selectRaw('COUNT(*)');
7149+
$sub = (new Builder())->from('events')->select('COUNT(*)');
71527150

71537151
$result = (new Builder())
71547152
->from('users')
@@ -7620,7 +7618,7 @@ public function testExactExistsSubquery(): void
76207618
{
76217619
$sub = (new Builder())
76227620
->from('orders')
7623-
->selectRaw('1')
7621+
->select('1')
76247622
->filter([Query::raw('`orders`.`user_id` = `users`.`id`')]);
76257623

76267624
$result = (new Builder())
@@ -9405,7 +9403,7 @@ public function testSelectRawWithBindings(): void
94059403
{
94069404
$result = (new Builder())
94079405
->from('events')
9408-
->selectRaw('toDate(?) AS ref_date', ['2024-01-01'])
9406+
->select('toDate(?) AS ref_date', ['2024-01-01'])
94099407
->build();
94109408
$this->assertBindingCount($result);
94119409

tests/Query/Builder/MySQLTest.php

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,7 +2050,7 @@ public function testEmptyBuilderNoFrom(): void
20502050
{
20512051
$this->expectException(ValidationException::class);
20522052
$this->expectExceptionMessage('No table specified');
2053-
(new Builder())->from('')->build();
2053+
(new Builder())->build();
20542054
}
20552055

20562056
public function testCursorWithLimitAndOffset(): void
@@ -5452,15 +5452,14 @@ public function testBuildWithNoFromNoFilters(): void
54525452
{
54535453
$this->expectException(ValidationException::class);
54545454
$this->expectExceptionMessage('No table specified');
5455-
(new Builder())->from('')->build();
5455+
(new Builder())->build();
54565456
}
54575457

54585458
public function testBuildWithOnlyLimit(): void
54595459
{
54605460
$this->expectException(ValidationException::class);
54615461
$this->expectExceptionMessage('No table specified');
54625462
(new Builder())
5463-
->from('')
54645463
->limit(10)
54655464
->build();
54665465
}
@@ -5470,7 +5469,6 @@ public function testBuildWithOnlyOffset(): void
54705469
$this->expectException(ValidationException::class);
54715470
$this->expectExceptionMessage('No table specified');
54725471
(new Builder())
5473-
->from('')
54745472
->offset(50)
54755473
->build();
54765474
}
@@ -5480,7 +5478,6 @@ public function testBuildWithOnlySort(): void
54805478
$this->expectException(ValidationException::class);
54815479
$this->expectExceptionMessage('No table specified');
54825480
(new Builder())
5483-
->from('')
54845481
->sortAsc('name')
54855482
->build();
54865483
}
@@ -5490,7 +5487,6 @@ public function testBuildWithOnlySelect(): void
54905487
$this->expectException(ValidationException::class);
54915488
$this->expectExceptionMessage('No table specified');
54925489
(new Builder())
5493-
->from('')
54945490
->select(['a', 'b'])
54955491
->build();
54965492
}
@@ -5500,7 +5496,6 @@ public function testBuildWithOnlyAggregationNoFrom(): void
55005496
$this->expectException(ValidationException::class);
55015497
$this->expectExceptionMessage('No table specified');
55025498
(new Builder())
5503-
->from('')
55045499
->count('*', 'total')
55055500
->build();
55065501
}
@@ -6017,7 +6012,7 @@ public function testEmptyTableWithJoin(): void
60176012
{
60186013
$this->expectException(ValidationException::class);
60196014
$this->expectExceptionMessage('No table specified');
6020-
(new Builder())->from('')->join('other', 'a', 'b')->build();
6015+
(new Builder())->join('other', 'a', 'b')->build();
60216016
}
60226017

60236018
public function testBuildWithoutFromCall(): void
@@ -7052,7 +7047,7 @@ public function testSelectRaw(): void
70527047
{
70537048
$result = (new Builder())
70547049
->from('orders')
7055-
->selectRaw('SUM(amount) AS total')
7050+
->select('SUM(amount) AS total')
70567051
->build();
70577052
$this->assertBindingCount($result);
70587053

@@ -7063,7 +7058,7 @@ public function testSelectRawWithBindings(): void
70637058
{
70647059
$result = (new Builder())
70657060
->from('orders')
7066-
->selectRaw('IF(amount > ?, 1, 0) AS big_order', [1000])
7061+
->select('IF(amount > ?, 1, 0) AS big_order', [1000])
70677062
->build();
70687063
$this->assertBindingCount($result);
70697064

@@ -7076,7 +7071,7 @@ public function testSelectRawCombinedWithSelect(): void
70767071
$result = (new Builder())
70777072
->from('orders')
70787073
->select(['id', 'customer_id'])
7079-
->selectRaw('SUM(amount) AS total')
7074+
->select('SUM(amount) AS total')
70807075
->build();
70817076
$this->assertBindingCount($result);
70827077

@@ -7094,7 +7089,7 @@ public function testSelectRawWithCaseExpression(): void
70947089
$result = (new Builder())
70957090
->from('users')
70967091
->select(['id'])
7097-
->selectRaw($case->sql, $case->bindings)
7092+
->select($case->sql, $case->bindings)
70987093
->build();
70997094
$this->assertBindingCount($result);
71007095

@@ -7104,7 +7099,7 @@ public function testSelectRawWithCaseExpression(): void
71047099

71057100
public function testSelectRawResetClears(): void
71067101
{
7107-
$builder = (new Builder())->from('t')->selectRaw('1 AS one');
7102+
$builder = (new Builder())->from('t')->select('1 AS one');
71087103
$builder->build();
71097104
$builder->reset();
71107105

@@ -7143,8 +7138,8 @@ public function testMultipleSelectRaw(): void
71437138
{
71447139
$result = (new Builder())
71457140
->from('t')
7146-
->selectRaw('COUNT(*) AS cnt')
7147-
->selectRaw('MAX(price) AS max_price')
7141+
->select('COUNT(*) AS cnt')
7142+
->select('MAX(price) AS max_price')
71487143
->build();
71497144
$this->assertBindingCount($result);
71507145

@@ -9057,7 +9052,7 @@ public function testSelectRawWithRegularSelect(): void
90579052
$result = (new Builder())
90589053
->from('t')
90599054
->select(['id'])
9060-
->selectRaw('NOW() as current_time')
9055+
->select('NOW() as current_time')
90619056
->build();
90629057
$this->assertBindingCount($result);
90639058

@@ -9068,7 +9063,7 @@ public function testSelectRawWithBindings2(): void
90689063
{
90699064
$result = (new Builder())
90709065
->from('t')
9071-
->selectRaw('COALESCE(?, ?) as result', ['a', 'b'])
9066+
->select('COALESCE(?, ?) as result', ['a', 'b'])
90729067
->build();
90739068
$this->assertBindingCount($result);
90749069

@@ -9153,7 +9148,7 @@ public function testFilterWithRawCombined(): void
91539148

91549149
public function testResetClearsRawSelects2(): void
91559150
{
9156-
$builder = (new Builder())->from('t')->selectRaw('1 AS one');
9151+
$builder = (new Builder())->from('t')->select('1 AS one');
91579152
$builder->build();
91589153
$builder->reset();
91599154

@@ -9911,7 +9906,7 @@ public function testSubqueryBindingOrderIsCorrect(): void
99119906
public function testSelectSubBindingOrder(): void
99129907
{
99139908
$sub = (new Builder())->from('orders')
9914-
->selectRaw('COUNT(*)')
9909+
->select('COUNT(*)')
99159910
->filter([Query::equal('orders.user_id', ['matched'])]);
99169911

99179912
$result = (new Builder())
@@ -10718,8 +10713,8 @@ public function testExactRawExpressions(): void
1071810713
{
1071910714
$result = (new Builder())
1072010715
->from('users')
10721-
->selectRaw('COUNT(*) AS `total`')
10722-
->selectRaw('MAX(`created_at`) AS `latest`')
10716+
->select('COUNT(*) AS `total`')
10717+
->select('MAX(`created_at`) AS `latest`')
1072310718
->filter([Query::equal('active', [true])])
1072410719
->orderByRaw('FIELD(`role`, ?, ?, ?)', ['admin', 'editor', 'viewer'])
1072510720
->build();
@@ -10816,7 +10811,7 @@ public function testExactSelectSubquery(): void
1081610811
{
1081710812
$sub = (new Builder())
1081810813
->from('orders')
10819-
->selectRaw('COUNT(*)')
10814+
->select('COUNT(*)')
1082010815
->filter([Query::raw('`orders`.`user_id` = `users`.`id`')]);
1082110816

1082210817
$result = (new Builder())
@@ -11265,8 +11260,8 @@ public function testExactAdvancedSelectRawWithGroupByRawAndHavingRaw(): void
1126511260
{
1126611261
$result = (new Builder())
1126711262
->from('orders')
11268-
->selectRaw('DATE(`created_at`) AS `order_date`')
11269-
->selectRaw('SUM(`total`) AS `daily_total`')
11263+
->select('DATE(`created_at`) AS `order_date`')
11264+
->select('SUM(`total`) AS `daily_total`')
1127011265
->groupByRaw('DATE(`created_at`)')
1127111266
->havingRaw('SUM(`total`) > ?', [1000])
1127211267
->build();
@@ -11717,8 +11712,8 @@ public function testResetClearsUpdateJoinAndDeleteUsing(): void
1171711712
public function testFromNone(): void
1171811713
{
1171911714
$result = (new Builder())
11720-
->fromNone()
11721-
->selectRaw('1 AS one')
11715+
->from()
11716+
->select('1 AS one')
1172211717
->build();
1172311718
$this->assertBindingCount($result);
1172411719

@@ -11790,8 +11785,8 @@ public function testNaturalJoinWithAlias(): void
1179011785

1179111786
public function testWithRecursiveSeedStep(): void
1179211787
{
11793-
$seed = (new Builder())->fromNone()->selectRaw('1 AS n');
11794-
$step = (new Builder())->from('cte')->selectRaw('n + 1')->filter([Query::lessThan('n', 10)]);
11788+
$seed = (new Builder())->from()->select('1 AS n');
11789+
$step = (new Builder())->from('cte')->select('n + 1')->filter([Query::lessThan('n', 10)]);
1179511790
$result = (new Builder())
1179611791
->from('cte')
1179711792
->withRecursiveSeedStep('cte', $seed, $step)
@@ -11917,7 +11912,7 @@ public function testFilterNotExistsSubquery(): void
1191711912

1191811913
public function testSelectSubquery(): void
1191911914
{
11920-
$sub = (new Builder())->fromNone()->selectRaw('COUNT(*)');
11915+
$sub = (new Builder())->from()->select('COUNT(*)');
1192111916
$result = (new Builder())
1192211917
->from('users')
1192311918
->select(['name'])
@@ -12760,8 +12755,8 @@ public function testCloneWithLateralJoins(): void
1276012755
public function testValidateTableFromNone(): void
1276112756
{
1276212757
$result = (new Builder())
12763-
->fromNone()
12764-
->selectRaw('CONNECTION_ID() AS cid')
12758+
->from()
12759+
->select('CONNECTION_ID() AS cid')
1276512760
->build();
1276612761
$this->assertBindingCount($result);
1276712762

@@ -13879,7 +13874,7 @@ public function testSelectRawWithBindingsPlusRegularSelect(): void
1387913874
$result = (new Builder())
1388013875
->from('t')
1388113876
->select(['name'])
13882-
->selectRaw('COALESCE(bio, ?) AS bio_display', ['N/A'])
13877+
->select('COALESCE(bio, ?) AS bio_display', ['N/A'])
1388313878
->filter([Query::equal('active', [true])])
1388413879
->build();
1388513880
$this->assertBindingCount($result);
@@ -14121,8 +14116,8 @@ public function testJoinWhereWithMultipleConditions(): void
1412114116
public function testFromNoneWithSelectRaw(): void
1412214117
{
1412314118
$result = (new Builder())
14124-
->fromNone()
14125-
->selectRaw('1 + 1 AS result')
14119+
->from()
14120+
->select('1 + 1 AS result')
1412614121
->build();
1412714122
$this->assertBindingCount($result);
1412814123

@@ -14529,9 +14524,9 @@ public function testMultipleSelectRawExpressions(): void
1452914524
{
1453014525
$result = (new Builder())
1453114526
->from('t')
14532-
->selectRaw('NOW() AS current_time')
14533-
->selectRaw('CONCAT(first_name, ?, last_name) AS full_name', [' '])
14534-
->selectRaw('? AS constant_val', [42])
14527+
->select('NOW() AS current_time')
14528+
->select('CONCAT(first_name, ?, last_name) AS full_name', [' '])
14529+
->select('? AS constant_val', [42])
1453514530
->build();
1453614531
$this->assertBindingCount($result);
1453714532

@@ -14580,12 +14575,12 @@ public function testExistsAndNotExistsCombined(): void
1458014575
{
1458114576
$existsSub = (new Builder())
1458214577
->from('orders')
14583-
->selectRaw('1')
14578+
->select('1')
1458414579
->filter([Query::raw('orders.user_id = users.id')]);
1458514580

1458614581
$notExistsSub = (new Builder())
1458714582
->from('bans')
14588-
->selectRaw('1')
14583+
->select('1')
1458914584
->filter([Query::raw('bans.user_id = users.id')]);
1459014585

1459114586
$result = (new Builder())

tests/Query/Builder/PostgreSQLTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5599,8 +5599,8 @@ public function testInsertAlias(): void
55995599
public function testFromNone(): void
56005600
{
56015601
$result = (new Builder())
5602-
->fromNone()
5603-
->selectRaw('1 AS one')
5602+
->from()
5603+
->select('1 AS one')
56045604
->build();
56055605

56065606
$this->assertSame('SELECT 1 AS one', $result->query);
@@ -5611,7 +5611,7 @@ public function testSelectRawWithBindings(): void
56115611
{
56125612
$result = (new Builder())
56135613
->from('t')
5614-
->selectRaw('COALESCE("name", ?) AS display_name', ['Unknown'])
5614+
->select('COALESCE("name", ?) AS display_name', ['Unknown'])
56155615
->build();
56165616

56175617
$this->assertStringContainsString('COALESCE("name", ?) AS display_name', $result->query);

tests/Query/Builder/SQLiteTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,7 @@ public function testSelectRawExpression(): void
17621762
{
17631763
$result = (new Builder())
17641764
->from('users')
1765-
->selectRaw("strftime('%Y', created_at) AS year")
1765+
->select("strftime('%Y', created_at) AS year")
17661766
->build();
17671767
$this->assertBindingCount($result);
17681768

0 commit comments

Comments
 (0)