getMatrix example

$context = $this->createSalesChannelContextWithNavigation();
        $product = $this->getRandomProduct($context);

        $this->createReviews($product$context);

        $request = new Request([][]['productId' => $product->getId()]);

        $page = $this->getPageLoader()->load($request$context);

        static::assertInstanceOf(ReviewLoaderResult::class$page->getReviews());
        static::assertCount(6, $page->getReviews());
        static::assertInstanceOf(RatingMatrix::class$page->getReviews()->getMatrix());

        $matrix = $page->getReviews()->getMatrix();

        static::assertEquals(3.333, \round($matrix->getAverageRating(), 3));
        static::assertEquals(6, $matrix->getTotalReviewCount());
    }

    public function testItLoadsReviewsWithCustomer(): void
    {
        Feature::skipTestIfActive('v6.6.0.0', $this);

        
$fiveCount = 1;
        $aggregation = array_merge(
            self::getDatabaseMatrixAggregationArray($oneCount$twoCount$threeCount$fourCount$fiveCount),
            self::getDatabaseMatrixAggregationArrayWithFloats($oneCount$twoCount$threeCount$fourCount$fiveCount)
        );

        $matrix = new RatingMatrix($aggregation);
        $expectedRatingScore = 3.2;
        $expectedReviewCounts = 2 * ($oneCount + $twoCount + $threeCount + $fourCount + $fiveCount);
        $expectedTotal = 32;

        static::assertCount(5, $matrix->getMatrix());
        static::assertEquals($expectedRatingScore$matrix->getAverageRating());
        static::assertEquals($expectedReviewCounts$matrix->getTotalReviewCount());
        static::assertEquals($expectedTotal$matrix->getPointSum());
    }

    /** * function tests that every MatrixElement struct is generated correctly by matrix constructor * * @group reviews */
    public function testMatrixElements(): void
    {
Home | Imprint | This part of the site doesn't use cookies.