createReview example


        $this->ids = new TestDataCollection();
        $this->connection = KernelLifecycleManager::getConnection();
    }

    public function testUpdate(): void
    {
        $migration = new Migration1692277552FixCustomerReviewCount();

        $this->createCustomer();
        $this->createProduct();
        $this->createReview($this->ids->create('review1'), true);
        $this->createReview($this->ids->create('review2'), false);
        $this->createReview($this->ids->create('review3'), true);

        $migration->update($this->connection);
        $migration->update($this->connection);

        $reviewCount = $this->connection->fetchOne(
            'SELECT `review_count` FROM `customer` WHERE `id` = :customerId;',
            ['customerId' => Uuid::fromHexToBytes($this->ids->get('customer'))],
        );
        static::assertEquals(2, $reviewCount);

        
$this->productReviewSubscriber->onReviewDeleted($event);
    }

    public function testCreateReviewWithInvalidEntityName(): void
    {
        $ids = [
            Uuid::randomHex(),
            Uuid::randomHex(),
        ];
        $this->productReviewCountService->expects(static::never())->method('updateReviewCount');
        $this->productReviewSubscriber->createReview($this->getEntityWrittenEvent($ids, true));
    }

    public function testCreateReview(): void
    {
        $ids = [
            Uuid::randomHex(),
            Uuid::randomHex(),
        ];
        $this->productReviewCountService->expects(static::once())->method('updateReviewCount')->with($ids);

        $this->productReviewSubscriber->createReview($this->getEntityWrittenEvent($ids));
    }

        } catch (\Throwable) {
        }
    }

    public function testUpdate(): void
    {
        $migration = new Migration1679584289AddCustomerReviewCount();

        $this->createCustomer();
        $this->createProduct();
        $this->createReview($this->ids->create('review1'));
        $this->createReview($this->ids->create('review2'));
        $this->createReview($this->ids->create('review3'));

        $migration->update($this->connection);
        $migration->update($this->connection);

        $reviewCount = $this->connection->fetchOne(
            'SELECT `review_count` FROM `customer` WHERE `id` = :customerId;',
            ['customerId' => Uuid::fromHexToBytes($this->ids->get('customer'))],
        );
        static::assertEquals(3, $reviewCount);

        
public function testUpsertReviewIndexerLogic(): void
    {
        $productId = Uuid::randomHex();
        $reviewAId = Uuid::randomHex();
        $reviewBId = Uuid::randomHex();

        $this->createProduct($productId);

        $pointsOnAReview = 5.0;
        $pointsOnBReview = 1.0;

        $this->createReview($reviewAId$pointsOnAReview$productId, true);

        $products = $this->productRepository->search(new Criteria([$productId])$this->salesChannel->getContext());

        static::assertInstanceOf(ProductEntity::class$product = $products->get($productId));
        static::assertEquals($pointsOnAReview$product->getRatingAverage());

        $expected = ($pointsOnAReview + $pointsOnBReview) / 2;
        $this->createReview($reviewBId$pointsOnBReview$productId, true);
        $products = $this->productRepository->search(new Criteria([$productId])$this->salesChannel->getContext());

        static::assertInstanceOf(ProductEntity::class$product = $products->get($productId));
        
$this->ids = new IdsCollection();

        $this->reviewCountService = $this->getContainer()->get(ProductReviewCountService::class);
    }

    public function testReviewCountIsUpdatedCorrectly(): void
    {
        $this->createProduct('p1');
        $this->createProduct('p2');

        $this->createCustomer('c1');
        $createdReviews[] = $this->createReview('c1', 'p1', true);
        $createdReviews[] = $this->createReview('c1', 'p2', false);

        $this->createCustomer('c2');
        $createdReviews[] = $this->createReview('c2', 'p2', true);

        $this->reviewCountService->updateReviewCount($createdReviews);

        $customerRepo = $this->getContainer()->get('customer.repository');
        /** @var CustomerCollection $customers */
        $customers = $customerRepo->search(new Criteria([$this->ids->get('c1')$this->ids->get('c2')]), Context::createDefaultContext());

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