Skip to content

Commit

Permalink
fix bug in testGetRatingDistribution and add some unverified reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
creme332 committed Jun 11, 2024
1 parent 769fd9b commit 3a7bc51
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions tests/models/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3a7bc51

Please sign in to comment.