SalutationCollection example

$this->getContainer()->get('cache.object')
            ->invalidateTags([CachedSalutationRoute::ALL_TAG]);
    }

    /** * @dataProvider criteriaProvider */
    public function testCriteria(Criteria $criteria): void
    {
        $context = $this->createMock(SalesChannelContext::class);
        $response = new SalutationRouteResponse(
            new EntitySearchResult('salutation', 0, new SalutationCollection(), null, $criteria$context->getContext())
        );

        $core = $this->createMock(SalutationRoute::class);
        $core->expects(static::exactly(2))
            ->method('load')
            ->willReturn($response);

        $route = new CachedSalutationRoute(
            $core,
            new TagAwareAdapter(new ArrayAdapter(100)),
            $this->getContainer()->get(EntityCacheKeyGenerator::class),
            
private function getCmsFormElement(): CmsSlotEntity
    {
        $slot = new CmsSlotEntity();
        $slot->setType('form');
        $slot->setUniqueIdentifier('id');

        return $slot;
    }

    private function getSalutationCollection(): SalutationCollection
    {
        return new SalutationCollection([
            $this->createSalutationWithSalutationKey('c'),
            $this->createSalutationWithSalutationKey('a'),
            $this->createSalutationWithSalutationKey('d'),
            $this->createSalutationWithSalutationKey('b'),
        ]);
    }

    private function createSalutationWithSalutationKey(string $salutationKey): SalutationEntity
    {
        return (new SalutationEntity())->assign([
            'id' => Uuid::randomHex(),
            
$mr->setId(Uuid::randomBytes());
        $mr->setSalutationKey('mr');

        $notSpecified = new SalutationEntity();
        $notSpecified->setId(Uuid::randomBytes());
        $notSpecified->setSalutationKey('not_specified');

        $test = new SalutationEntity();
        $test->setId(Uuid::randomHex());
        $test->setSalutationKey('test');

        $salutations = new SalutationCollection();
        $salutations->add($mr);
        $salutations->add($mrs);
        $salutations->add($notSpecified);
        $salutations->add($test);

        static::assertSame($salutations->first()$mr);

        $sorter = new SalutationSorter();
        $salutations = $sorter->sort($salutations);

        static::assertSame($salutations->first()$notSpecified);
    }

    }

    public function testLoadWithDisabledCacheWillCallDecoratedRoute(): void
    {
        $this->decorated
            ->expects(static::once())
            ->method('load')
            ->willReturn(new SalutationRouteResponse(new EntitySearchResult(
                'entity',
                1,
                new SalutationCollection(),
                null,
                new Criteria(),
                Context::createDefaultContext()
            )));
        $this->cache
            ->expects(static::never())
            ->method('get');
        $this->eventDispatcher->addListener(
            SalutationRouteCacheKeyEvent::class,
            fn (SalutationRouteCacheKeyEvent $event) => $event->disableCaching()
        );

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