Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion tests/AggregationBlogPost/FuelExample1Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

namespace AggregationBlogPost;

use MongoDB\BSON\Type;
use MongoDB\Builder\Accumulator;
use MongoDB\Builder\Expression;
use MongoDB\Builder\Pipeline;
use MongoDB\Builder\Query;
use MongoDB\Builder\Stage;
use MongoDB\Builder\Stage\GroupStage;
use MongoDB\Builder\Type\ExpressionInterface;

Check failure on line 11 in tests/AggregationBlogPost/FuelExample1Test.php

View workflow job for this annotation

GitHub Actions / phpcs

Type MongoDB\Builder\Type\ExpressionInterface is not used in this file.
use MongoDB\Tests\TestCase;
use stdClass;
use function MongoDB\object;

Check failure on line 14 in tests/AggregationBlogPost/FuelExample1Test.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 line between different types of use statement, found 0.

class FuelExample1Test extends TestCase
{
Expand All @@ -25,7 +24,7 @@
'year' => ['$year' => '$reportDate'],
'month' => ['$month' => '$reportDate'],
'fuelType' => '$fuelType',
'brand' => '$station.brand'

Check failure on line 27 in tests/AggregationBlogPost/FuelExample1Test.php

View workflow job for this annotation

GitHub Actions / phpcs

Multi-line arrays must have a trailing comma after the last element.
],
'lowest' => ['$min' => '$price'],
'highest' => ['$max' => '$price'],
Expand Down Expand Up @@ -117,9 +116,9 @@
Expression::doubleFieldPath('highest'),
Expression::doubleFieldPath('lowest'),
),
)

Check failure on line 119 in tests/AggregationBlogPost/FuelExample1Test.php

View workflow job for this annotation

GitHub Actions / phpcs

Multi-line function calls must have a trailing comma after the last parameter.
)

Check failure on line 120 in tests/AggregationBlogPost/FuelExample1Test.php

View workflow job for this annotation

GitHub Actions / phpcs

Multi-line function calls must have a trailing comma after the last parameter.
)

Check failure on line 121 in tests/AggregationBlogPost/FuelExample1Test.php

View workflow job for this annotation

GitHub Actions / phpcs

Multi-line function calls must have a trailing comma after the last parameter.
),
Stage::addFields(
prices: Expression::arrayToObject(
Expand Down Expand Up @@ -599,4 +598,33 @@
),
);
}

public function testFirstClassCallableSyntax(): void
{
$reportDate = Expression::dateFieldPath('reportDate');
$price = Expression::doubleFieldPath('price');
$fuelType = Expression::fieldPath('fuelType');
$brand = Expression::fieldPath('station.brand');

$group = Stage::group(...);
$year = Expression::year(...);
$month = Expression::month(...);
$min = Accumulator::min(...);
$max = Accumulator::max(...);
$avg = Accumulator::avg(...);
$sum = Accumulator::sum(...);

$group(
_id: object(
year: $year($reportDate),
month: $month($reportDate),
fuelType: $fuelType,
brand: $brand,
),
lowest: $min($price),
highest: $max($price),
average: $avg($price),
count: $sum(1),
);
}
}
Loading
Loading