getAverageRating example

/** * check that matrix calculates correctly * * @dataProvider getRatings * * @group reviews */
    public function testMatrixCalculation(float $expectedScore, int $reviewCounts, float $total, array $aggregation): void
    {
        $matrix = new RatingMatrix($aggregation);
        $expectedScore = round($expectedScore, 4);
        $actual = round($matrix->getAverageRating(), 4);
        static::assertEquals($expectedScore$actual, 'expected score does not match');
        static::assertEquals($reviewCounts$matrix->getTotalReviewCount(), 'expected total review count does not match');
        static::assertEquals($total$matrix->getPointSum(), 'expected total review points does not match');
    }

    /** * dataprovider for testMatrixCalculation */
    public static function getRatings(): array
    {
        return [
            
$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);

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

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

        
Home | Imprint | This part of the site doesn't use cookies.