WarmUpMessage example

->andWhere('COALESCE (`product`.active, `pp`.active)')
            ->distinct()
            ->setMaxResults(10);

        $ids = $iterator->fetch();
        if (empty($ids)) {
            return null;
        }

        $ids = array_map(fn ($id) => ['productId' => $id]$ids);

        return new WarmUpMessage('frontend.detail.page', $ids$iterator->getOffset());
    }
}
public function testWarmUpNoId(): void
    {
        $salesChannelDomain = new SalesChannelDomainEntity();
        $salesChannelDomain->setId(Uuid::randomHex());
        $salesChannelDomain->setUniqueIdentifier(Uuid::randomHex());
        $salesChannelDomain->setUrl('https://localhost');
        $context = Context::createDefaultContext();
        $criteria = new Criteria();
        $cacheId = Uuid::randomHex();
        $this->cacheIdLoader->expects(static::once())->method('load')->willReturn($cacheId);

        $warmUpMessage = new WarmUpMessage('/testRoute', []);
        $warmUpMessageExpected = new WarmUpMessage('/testRoute', []);
        $warmUpMessageExpected->setCacheId($cacheId);
        $warmUpMessageExpected->setDomain('https://localhost');

        $criteria->addFilter(
            new EqualsFilter('salesChannel.typeId', Defaults::SALES_CHANNEL_TYPE_STOREFRONT),
        );

        $this->productRouteWarmerMock->expects(static::exactly(2))->method('createMessage')
            ->willReturnOnConsecutiveCalls($warmUpMessage, null);

        
$this->requestTransformer,
            $this->cacheIdLoader,
            $this->cacheTagCollection
        );
    }

    public function testInvokeWithNotMatchingCacheIds(): void
    {
        $this->cacheIdLoader->expects(static::once())->method('load')->willReturn('cacheId');
        $this->kernel->expects(static::never())->method('handle');

        $message = new WarmUpMessage(
            'product.list',
            [['page' => '1']['page' => '2']],
        );
        $message->setCacheId('differentCacheId');

        $this->handler->__invoke($message);
    }

    public function testInvokeWillCallRoutes(): void
    {
        $this->cacheIdLoader->expects(static::once())->method('load')->willReturn('cacheId');

        
$query
            ->andWhere('`category`.active = 1')
            ->setMaxResults(10);

        $ids = $iterator->fetch();
        if (empty($ids)) {
            return null;
        }

        $ids = array_map(fn ($id) => ['navigationId' => $id]$ids);

        return new WarmUpMessage('frontend.navigation.page', $ids$iterator->getOffset());
    }
}
Home | Imprint | This part of the site doesn't use cookies.