From 3a7bc517ddc3556ac586184820df626f862d020b Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Tue, 11 Jun 2024 07:48:26 +0400 Subject: [PATCH] fix bug in testGetRatingDistribution and add some unverified reviews --- tests/models/ProductTest.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/models/ProductTest.php b/tests/models/ProductTest.php index 2aca691..8ab51ac 100644 --- a/tests/models/ProductTest.php +++ b/tests/models/ProductTest.php @@ -221,25 +221,24 @@ public function testValidate(): void */ public function testGetRatingDistribution(): void { + // reset data from setUp + self::resetDatabase(); + // Create a new product for testing $product = self::createProduct(); + $this->dummy_client = self::createClient(); // Create mock review data with different ratings - $reviewsData = [ - ['rating' => 5], - ['rating' => 4], - ['rating' => 3], - ['rating' => 2], - ['rating' => 1], - ['rating' => 5], - ['rating' => 4], - ['rating' => 3], - ['rating' => 4], - ['rating' => 5], - ]; + $verifiedReviewRatings = [5, 4, 3, 2, 1, 5, 4, 3, 4, 5]; // Insert mock review data into the database - foreach ($reviewsData as $reviewData) { - self::createReview($product, $this->dummy_client, $reviewData['rating'], true); + foreach ($verifiedReviewRatings as $reviewData) { + self::createReview($product, $this->dummy_client, $reviewData, true); + } + + // Create a random number of unverified reviews with different ratings + for ($i = 0; $i < self::$faker->numberBetween(0, 10); $i++) { + $rating = self::$faker->numberBetween(1, 5); + self::createReview($product, self::createClient(), $rating); } // Retrieve the rating distribution for the product