Skip to content

Commit 33add90

Browse files
abnegateclaude
andcommitted
test: rewrite join call sites to the utopia-php/query 0.7 single form
CR-10/CR-11 (codemod, rename rules restricted to Joins, JoinAlias and CompileExpressions) rewrote the joins to Query::join($t, 'alias', [Query::on(...)]) and getJoinAlias() to getAlias(). Joins without an alias got the j<n> alias 7.x generated for them; the two the codemod could not place (a join chosen by match()) take j0, their position in the read. By hand: - 0.6 column-form Query objects built with `new Query(...)` and dynamic Query::$method() joins move to ON lists. - ON lists holding search, vector, limit and other non-conditions now throw in the factory (BUG-05). QueryValidationTest asserts that refusal and keeps checking the read paths with a hand-built join; the IndexedQueries, JoinedAttributes and FlatAggregate cases build theirs by hand to keep exercising the validator and builder refusals. - The column-form-only messages (no right column, non-string column) are checked through an on() condition; the adapter now reports both as 'Join ON requires left and right columns'. - JoinChainTest: joins are keyed by alias; the table fallback is gone. Preserved-behaviour files (M6) change only in the join call form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c08de04 commit 33add90

67 files changed

Lines changed: 772 additions & 759 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎tests/e2e/Adapter/Scopes/AggregationTests.php‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ public function testInnerJoinBasic(): void
905905
$this->createCustomers($database, 'ij_customers');
906906

907907
$results = $database->find('ij_orders', [
908-
Query::join('ij_customers', 'customer_uid', '$id'),
908+
Query::join('ij_customers', 'j0', [Query::on('customer_uid', '$id')]),
909909
Query::count('*', 'total'),
910910
]);
911911

@@ -927,7 +927,7 @@ public function testInnerJoinWithGroupBy(): void
927927
$this->createCustomers($database, 'ij_grp_c');
928928

929929
$results = $database->find('ij_grp_o', [
930-
Query::join('ij_grp_c', 'customer_uid', '$id'),
930+
Query::join('ij_grp_c', 'j0', [Query::on('customer_uid', '$id')]),
931931
Query::sum('total', 'total_spent'),
932932
Query::count('*', 'order_count'),
933933
Query::groupBy(['customer_uid']),
@@ -960,7 +960,7 @@ public function testInnerJoinWithFilter(): void
960960
$this->createCustomers($database, 'ij_filt_c');
961961

962962
$results = $database->find('ij_filt_o', [
963-
Query::join('ij_filt_c', 'customer_uid', '$id'),
963+
Query::join('ij_filt_c', 'j0', [Query::on('customer_uid', '$id')]),
964964
Query::equal('status', ['completed']),
965965
Query::sum('total', 'revenue'),
966966
Query::groupBy(['customer_uid']),
@@ -992,7 +992,7 @@ public function testInnerJoinWithHaving(): void
992992
$this->createCustomers($database, 'ij_hav_c');
993993

994994
$results = $database->find('ij_hav_o', [
995-
Query::join('ij_hav_c', 'customer_uid', '$id'),
995+
Query::join('ij_hav_c', 'j0', [Query::on('customer_uid', '$id')]),
996996
Query::sum('total', 'total_spent'),
997997
Query::groupBy(['customer_uid']),
998998
Query::having([Query::greaterThan('total_spent', 1000)]),
@@ -1019,7 +1019,7 @@ public function testInnerJoinProductReviewStats(): void
10191019
$this->createReviews($database, 'ij_prs_r');
10201020

10211021
$results = $database->find('ij_prs_p', [
1022-
Query::join('ij_prs_r', '$id', 'product_uid'),
1022+
Query::join('ij_prs_r', 'j0', [Query::on('$id', 'product_uid')]),
10231023
Query::count('*', 'review_count'),
10241024
Query::avg('score', 'avg_score'),
10251025
Query::groupBy(['name']),
@@ -1052,7 +1052,7 @@ public function testLeftJoinBasic(): void
10521052
$this->createReviews($database, 'lj_basic_r');
10531053

10541054
$results = $database->find('lj_basic_p', [
1055-
Query::leftJoin('lj_basic_r', '$id', 'product_uid'),
1055+
Query::leftJoin('lj_basic_r', 'j0', [Query::on('$id', 'product_uid')]),
10561056
Query::count('*', 'review_count'),
10571057
Query::groupBy(['name']),
10581058
]);
@@ -1086,7 +1086,7 @@ public function testLeftJoinWithFilter(): void
10861086
$this->createOrders($database, 'lj_filt_o');
10871087

10881088
$results = $database->find('lj_filt_p', [
1089-
Query::leftJoin('lj_filt_o', '$id', 'product_uid'),
1089+
Query::leftJoin('lj_filt_o', 'j0', [Query::on('$id', 'product_uid')]),
10901090
Query::equal('category', ['electronics']),
10911091
Query::count('*', 'order_count'),
10921092
Query::sum('quantity', 'total_qty'),
@@ -1119,7 +1119,7 @@ public function testLeftJoinCustomerOrderSummary(): void
11191119
$this->createOrders($database, 'lj_cos_o');
11201120

11211121
$results = $database->find('lj_cos_c', [
1122-
Query::leftJoin('lj_cos_o', '$id', 'customer_uid'),
1122+
Query::leftJoin('lj_cos_o', 'j0', [Query::on('$id', 'customer_uid')]),
11231123
Query::count('*', 'order_count'),
11241124
Query::groupBy(['name']),
11251125
]);
@@ -1187,7 +1187,7 @@ public function testJoinAggregationWithPermissionsGrouped(): void
11871187
$database->getAuthorization()->addRole(Role::user('viewer')->toString());
11881188

11891189
$results = $database->find('jp_apg_o', [
1190-
Query::join('jp_apg_c', 'customer_uid', '$id'),
1190+
Query::join('jp_apg_c', 'j0', [Query::on('customer_uid', '$id')]),
11911191
Query::sum('amount', 'total'),
11921192
Query::count('*', 'cnt'),
11931193
Query::groupBy(['customer_uid']),
@@ -1248,7 +1248,7 @@ public function testLeftJoinPermissionFiltered(): void
12481248
$database->getAuthorization()->addRole(Role::user('tester')->toString());
12491249

12501250
$results = $database->find('jp_ljpf_p', [
1251-
Query::leftJoin('jp_ljpf_r', '$id', 'product_uid'),
1251+
Query::leftJoin('jp_ljpf_r', 'j0', [Query::on('$id', 'product_uid')]),
12521252
Query::count('*', 'review_count'),
12531253
Query::groupBy(['name']),
12541254
]);
@@ -2111,10 +2111,10 @@ public function testMainAttributeAggregatedUnderItsOwnNameOverAJoinIsReadFromThe
21112111
}
21122112

21132113
foreach ([
2114-
'inner join' => [Query::join($joined, 'link', 'link', '=', 'other'), 10, 1],
2115-
'left join' => [Query::leftJoin($joined, 'link', 'link', '=', 'other'), 30, 2],
2116-
'right join' => [Query::rightJoin($joined, 'link', 'link', '=', 'other'), 10, 2],
2117-
'full outer join' => [Query::fullOuterJoin($joined, 'link', 'link', '=', 'other'), 30, 3],
2114+
'inner join' => [Query::join($joined, 'other', [Query::on('link', 'link')]), 10, 1],
2115+
'left join' => [Query::leftJoin($joined, 'other', [Query::on('link', 'link')]), 30, 2],
2116+
'right join' => [Query::rightJoin($joined, 'other', [Query::on('link', 'link')]), 10, 2],
2117+
'full outer join' => [Query::fullOuterJoin($joined, 'other', [Query::on('link', 'link')]), 30, 3],
21182118
] as $type => [$join, $total, $rows]) {
21192119
$own = $database->find($main, [$join, Query::sum('score', 'score')]);
21202120
$this->assertCount(1, $own, $type);
@@ -2208,7 +2208,7 @@ public function testSelectNextToAnAggregateMustNameAGroupedAttribute(): void
22082208
if ($database->getAdapter()->supports(Capability::Joins)) {
22092209
$orders = 'agg_select_ungrouped_orders';
22102210
$this->createOrders($database, $orders);
2211-
$product = Query::join($collection, 'product_uid', '$id', '=', 'product');
2211+
$product = Query::join($collection, 'product', [Query::on('product_uid', '$id')]);
22122212

22132213
foreach ([
22142214
['product.name', [$product, Query::count('*', 'total'), Query::groupBy(['status']), Query::select(['product.name'])]],
@@ -2293,7 +2293,7 @@ public function testRelationshipWildcardsNextToAnAggregateAddNothingToTheRows():
22932293
$this->assertSame(['status', 'total'], $this->sortedAttributeNames($groups[0]));
22942294

22952295
if ($adapter->supports(Capability::Joins)) {
2296-
$joined = $database->find($customers, [Query::fullOuterJoin($accounts, 'account', '$id', '=', 'owned'), Query::count('*', 'total'), Query::select($selects)]);
2296+
$joined = $database->find($customers, [Query::fullOuterJoin($accounts, 'owned', [Query::on('account', '$id')]), Query::count('*', 'total'), Query::select($selects)]);
22972297
$this->assertCount(1, $joined);
22982298
$this->assertSame(['total'], $this->sortedAttributeNames($joined[0]));
22992299
$this->assertSame(3, $this->intAttribute($joined[0], 'total'));
@@ -2335,8 +2335,8 @@ public function testGroupedSelectReturnsEachGroupOnceWithItsAggregate(): void
23352335
$this->createOrders($database, $orders);
23362336

23372337
foreach ([
2338-
'inner join' => [Query::join($collection, 'product_uid', '$id', '=', 'product'), [2, 3, 5]],
2339-
'full outer join' => [Query::fullOuterJoin($collection, 'product_uid', '$id', '=', 'product'), [3, 3, 5]],
2338+
'inner join' => [Query::join($collection, 'product', [Query::on('product_uid', '$id')]), [2, 3, 5]],
2339+
'full outer join' => [Query::fullOuterJoin($collection, 'product', [Query::on('product_uid', '$id')]), [3, 3, 5]],
23402340
] as $type => [$product, $totals]) {
23412341
$groups = $database->find($orders, [$product, Query::count('*', 'total'), Query::groupBy(['product.category']), Query::select(['product.category']), Query::orderAsc('product.category')]);
23422342
$this->assertSame(['books', 'clothing', 'electronics'], \array_map(fn (Document $group): mixed => $group->getAttribute('category'), $groups), $type);

‎tests/e2e/Adapter/Scopes/AttributeTests.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ public function testDottedAttributeKeysBesideJoinAliases(): void
458458
));
459459
$database->createDocument($orders, new Document(['$id' => 'o1', 'personId' => 'a', 'total' => 7]));
460460

461-
$join = Query::join($orders, '$id', 'personId', '=', 'ord');
462-
$leftJoin = Query::leftJoin($orders, '$id', 'personId', '=', 'ord');
461+
$join = Query::join($orders, 'ord', [Query::on('$id', 'personId')]);
462+
$leftJoin = Query::leftJoin($orders, 'ord', [Query::on('$id', 'personId')]);
463463

464464
$this->assertSame(['a'], $this->sortedIds($database->find($collection, [$join, Query::equal('dots.name', ['v'])])));
465465
$this->assertSame(1, $database->count($collection, [$join, Query::equal('dots.name', ['v'])]));

‎tests/e2e/Adapter/Scopes/DocumentTests.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10407,8 +10407,8 @@ public function testSumResolvesABareNameOnlyAJoinDeclares(): void
1040710407
}
1040810408
$database->createDocument($extras, new Document(['$id' => 'a', '$permissions' => [], 'code' => 'a', 'price' => 100]));
1040910409

10410-
$item = Query::join($items, 'item', 'code', '=', 'it');
10411-
$extra = Query::join($extras, 'item', 'code', '=', 'ex');
10410+
$item = Query::join($items, 'it', [Query::on('item', 'code')]);
10411+
$extra = Query::join($extras, 'ex', [Query::on('item', 'code')]);
1041210412

1041310413
$this->assertEquals(40, $database->sum($orders, 'price', [$item]));
1041410414
$this->assertEquals(40, $database->sum($orders, 'it.price', [$item]));
@@ -10474,7 +10474,7 @@ public function testJoinedGroupSharingAMainGroupNameKeepsItsQualifiedName(): voi
1047410474
return \array_map(static fn (Document $document): array => $document->getArrayCopy(), $documents);
1047510475
};
1047610476

10477-
foreach (['join' => Query::join($items, 'item', 'code', '=', 'it'), 'full outer join' => Query::fullOuterJoin($items, 'item', 'code', '=', 'it')] as $case => $join) {
10477+
foreach (['join' => Query::join($items, 'it', [Query::on('item', 'code')]), 'full outer join' => Query::fullOuterJoin($items, 'it', [Query::on('item', 'code')])] as $case => $join) {
1047810478
$this->assertEquals(
1047910479
[['orders' => 2, 'name' => 'x', 'it.name' => 'apple'], ['orders' => 1, 'name' => 'y', 'it.name' => 'banana']],
1048010480
$rows($database->find($orders, [$join, Query::count('*', 'orders'), Query::groupBy(['name', 'it.name']), Query::orderAsc('name')])),
@@ -10538,8 +10538,8 @@ public function testJoinWildcardSelectAndBareJoinedOrder(): void
1053810538
}
1053910539
$database->createDocument($extras, new Document(['$id' => 'a', '$permissions' => [], 'code' => 'a', 'price' => 100]));
1054010540

10541-
$item = Query::join($items, 'item', 'code', '=', 'it');
10542-
$extra = Query::join($extras, 'item', 'code', '=', 'ex');
10541+
$item = Query::join($items, 'it', [Query::on('item', 'code')]);
10542+
$extra = Query::join($extras, 'ex', [Query::on('item', 'code')]);
1054310543
$ids = static function (array $documents): array {
1054410544
/** @var array<Document> $documents */
1054510545
return \array_map(static fn (Document $document): string => $document->getId(), $documents);
@@ -10554,7 +10554,7 @@ public function testJoinWildcardSelectAndBareJoinedOrder(): void
1055410554
$this->assertNull($rows[1]->getAttribute('quantity'));
1055510555

1055610556
$this->assertSame(['o2', 'o1', 'o3'], $ids($database->find($orders, [$item, Query::orderDesc('price'), Query::orderAsc('$id')])));
10557-
$this->assertSame(['o2', 'o1', 'o3'], $ids($database->find($orders, [Query::fullOuterJoin($items, 'item', 'code', '=', 'it'), Query::orderDesc('price'), Query::orderAsc('$id')])));
10557+
$this->assertSame(['o2', 'o1', 'o3'], $ids($database->find($orders, [Query::fullOuterJoin($items, 'it', [Query::on('item', 'code')]), Query::orderDesc('price'), Query::orderAsc('$id')])));
1055810558
$this->assertSame(['o2', 'o1', 'o3'], $ids($database->find($orders, [$item, Query::orderDesc('name'), Query::orderAsc('$id')])), 'a name the main collection declares reads the main table');
1055910559
$this->assertEquals(
1056010560
[['orders' => 1, 'code' => 'b'], ['orders' => 2, 'code' => 'a']],

0 commit comments

Comments
 (0)