Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Commit b835a98

Browse files
committed
Revert array_map
1 parent 671edfa commit b835a98

File tree

2 files changed

+59
-30
lines changed

2 files changed

+59
-30
lines changed

tests/Builder/Stage/ProjectStageTest.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,31 @@ public function testIncludeComputedFields(): void
7575
Stage::project(
7676
title: 1,
7777
isbn: object(
78-
prefix: Expression::substr(Expression::stringFieldPath('isbn'), 0, 3),
79-
group: Expression::substr(Expression::stringFieldPath('isbn'), 3, 2),
80-
publisher: Expression::substr(Expression::stringFieldPath('isbn'), 5, 4),
81-
title: Expression::substr(Expression::stringFieldPath('isbn'), 9, 3),
82-
checkDigit: Expression::substr(Expression::stringFieldPath('isbn'), 12, 1),
78+
prefix: Expression::substr(
79+
Expression::stringFieldPath('isbn'),
80+
0,
81+
3,
82+
),
83+
group: Expression::substr(
84+
Expression::stringFieldPath('isbn'),
85+
3,
86+
2,
87+
),
88+
publisher: Expression::substr(
89+
Expression::stringFieldPath('isbn'),
90+
5,
91+
4,
92+
),
93+
title: Expression::substr(
94+
Expression::stringFieldPath('isbn'),
95+
9,
96+
3,
97+
),
98+
checkDigit: Expression::substr(
99+
Expression::stringFieldPath('isbn'),
100+
12,
101+
1,
102+
),
83103
),
84104
lastName: Expression::stringFieldPath('author.last'),
85105
copiesSold: Expression::intFieldPath('copies'),
@@ -119,7 +139,10 @@ public function testProjectNewArrayFields(): void
119139
{
120140
$pipeline = new Pipeline(
121141
Stage::project(
122-
myArray: [Expression::fieldPath('x'), Expression::fieldPath('y')],
142+
myArray: [
143+
Expression::fieldPath('x'),
144+
Expression::fieldPath('y'),
145+
],
123146
),
124147
);
125148

tests/Builder/Stage/UnionWithStageTest.php

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
use MongoDB\Builder\Stage;
1111
use MongoDB\Tests\Builder\PipelineTestCase;
1212

13-
use function array_map;
14-
use function array_merge;
1513
use function MongoDB\object;
16-
use function range;
1714

1815
/**
1916
* Test $unionWith stage
@@ -22,33 +19,42 @@ class UnionWithStageTest extends PipelineTestCase
2219
{
2320
public function testReport1AllSalesByYearAndStoresAndItems(): void
2421
{
25-
$pipeline = new Pipeline(...array_merge(
26-
[
27-
Stage::set(
28-
_id: '2017',
22+
$pipeline = new Pipeline(
23+
Stage::set(
24+
_id: '2017',
25+
),
26+
Stage::unionWith(
27+
coll: 'sales_2018',
28+
pipeline: new Pipeline(
29+
Stage::set(
30+
_id: '2018',
31+
),
2932
),
30-
],
31-
array_map(
32-
fn ($year) => Stage::unionWith(
33-
coll: 'sales_' . $year,
34-
pipeline: new Pipeline(
35-
Stage::set(
36-
_id: (string) $year,
37-
),
33+
),
34+
Stage::unionWith(
35+
coll: 'sales_2019',
36+
pipeline: new Pipeline(
37+
Stage::set(
38+
_id: '2019',
3839
),
3940
),
40-
range(2018, 2020),
4141
),
42-
[
43-
Stage::sort(
44-
object(
45-
_id: 1,
46-
store: 1,
47-
item: 1,
42+
Stage::unionWith(
43+
coll: 'sales_2020',
44+
pipeline: new Pipeline(
45+
Stage::set(
46+
_id: '2020',
4847
),
4948
),
50-
],
51-
));
49+
),
50+
Stage::sort(
51+
object(
52+
_id: 1,
53+
store: 1,
54+
item: 1,
55+
),
56+
),
57+
);
5258

5359
$this->assertSamePipeline(Pipelines::UnionWithReport1AllSalesByYearAndStoresAndItems, $pipeline);
5460
}

0 commit comments

Comments
 (0)