CountResult example

return new MaxResult($aggregation->getName()$value);

            case $aggregation instanceof MinAggregation:
                $value = isset($rows[0]) ? $rows[0][$name] : 0;

                return new MinResult($aggregation->getName()$value);

            case $aggregation instanceof CountAggregation:
                $value = isset($rows[0]) ? $rows[0][$name] : 0;

                return new CountResult($aggregation->getName()(int) $value);

            case $aggregation instanceof StatsAggregation:
                if (empty($rows)) {
                    return new StatsResult($aggregation->getName(), 0, 0, 0.0, 0.0);
                }

                $min = $rows[0][$name . '.min'] ?? null;
                $max = $rows[0][$name . '.max'] ?? null;
                $avg = isset($rows[0][$name . '.avg']) ? (float) $rows[0][$name . '.avg'] : null;
                $sum = isset($rows[0][$name . '.sum']) ? (float) $rows[0][$name . '.sum'] : null;

                
static::expectException(PageNotFoundException::class);

        $this->controller->category($ids->get('category')new Request()$this->createMock(SalesChannelContext::class));
    }

    public function testFilterReturn(): void
    {
        $ids = new IdsCollection();

        $testAggregations = new \ArrayObject([
            'count' => new CountResult('count', 2),
            'sum' => new SumResult('sum', 2.3),
        ]);
        $productListingResultMock = $this->createMock(ProductListingResult::class);
        $productListingResultMock->method('getAggregations')->willReturn(
            new AggregationResultCollection(
                $testAggregations
            )
        );

        $request = new Request();

        
private function hydrateAggregation(Aggregation $aggregation, array $result, Context $context): ?AggregationResult
    {
        switch (true) {
            case $aggregation instanceof StatsAggregation:
                return new StatsResult($aggregation->getName()$result['min']$result['max']$result['avg']$result['sum']);

            case $aggregation instanceof AvgAggregation:
                return new AvgResult($aggregation->getName()$result['value']);

            case $aggregation instanceof CountAggregation:
                return new CountResult($aggregation->getName()$result['value']);

            case $aggregation instanceof EntityAggregation:
                return $this->hydrateEntityAggregation($aggregation$result$context);

            case $aggregation instanceof MaxAggregation:
                return new MaxResult($aggregation->getName()$result['value']);

            case $aggregation instanceof MinAggregation:
                return new MinResult($aggregation->getName()$result['value']);

            case $aggregation instanceof SumAggregation:
                
Home | Imprint | This part of the site doesn't use cookies.