EventDispatcher example

public function testMapping(): void
    {
        $connection = $this->createMock(Connection::class);
        $connection->expects(static::once())
            ->method('fetchAllKeyValue')
            ->willReturn(['test' => CustomFieldTypes::INT]);

        $newImplementation = new EsProductDefinition(
            $this->createMock(ProductDefinition::class),
            $connection,
            [],
            new EventDispatcher(),
            $this->createMock(AbstractProductSearchQueryBuilder::class),
            [
                'en' => 'english',
                'de' => 'german',
            ]
        );

        $definition = new ElasticsearchProductDefinition(
            $this->createMock(ProductDefinition::class),
            $connection,
            [],
            


        $storeApiCustomFieldMapper = $this->createMock(StoreApiCustomFieldMapper::class);
        $storeApiCustomFieldMapper
            ->expects(static::once())
            ->method('map')
            ->with('customer', $customFields)
            ->willReturn(['test1' => '1']);

        $change = new ChangeCustomerProfileRoute(
            $customerRepository,
            new EventDispatcher(),
            $this->createMock(DataValidator::class),
            $this->createMock(CustomerValidationFactory::class),
            $storeApiCustomFieldMapper,
            $this->createMock(EntityRepository::class),
        );

        $customer = new CustomerEntity();
        $customer->setId('customer1');
        $data = new RequestDataBag([
            'customFields' => $customFields,
            'salutationId' => '1',
        ]);

class StockUpdaterTest extends TestCase
{
    private EventDispatcher $dispatcher;

    private IdsCollection $ids;

    protected function setUp(): void
    {
        $this->dispatcher = new EventDispatcher();
        $this->ids = new IdsCollection();
    }

    public function testGetSubscribedEvents(): void
    {
        $events = StockUpdater::getSubscribedEvents();

        static::assertArrayHasKey(CheckoutOrderPlacedEvent::class$events);
        static::assertArrayHasKey(StateMachineTransitionEvent::class$events);
        static::assertArrayHasKey(PreWriteValidationEvent::class$events);
        static::assertArrayHasKey(OrderEvents::ORDER_LINE_ITEM_WRITTEN_EVENT, $events);
        
CustomFieldSetDefinition::class,
        MailTemplateDefinition::class,
        MailHeaderFooterDefinition::class,
    ];

    private EventDispatcher $dispatcher;

    private DemodataCommand $command;

    protected function setUp(): void
    {
        $this->dispatcher = new EventDispatcher();
        $this->command = new DemodataCommand(
            $this->createMock(DemodataService::class),
            $this->dispatcher,
            $this->getName() === 'testShowNoticeWhenNotProd' ? 'dev' : 'prod'
        );
    }

    public function testShowNoticeWhenNotProd(): void
    {
        $eventCalled = false;
        $this->dispatcher->addListener(DemodataRequestCreatedEvent::classstatic function D) use (&$eventCalled): void {
            
$client
            ->method('indices')
            ->willReturn($indices);

        $index = new IndexCreator(
            $client,
            [
                'settings' => $constructorConfig,
            ],
            $this->createMock(IndexMappingProvider::class),
            new EventDispatcher()
        );

        $definition = $this->createMock(ElasticsearchProductDefinition::class);
        $index->createIndex($definition, 'foo', 'bla', Context::createDefaultContext());
    }

    public function testIndexCreationFiresEvents(): void
    {
        $client = $this->createMock(Client::class);
        $indices = $this->createMock(IndicesNamespace::class);
        $indices
            
private CachedNavigationRoute $cachedRoute;

    private SalesChannelContext $context;

    private NavigationRouteResponse $response;

    protected function setUp(): void
    {
        $this->decorated = $this->createMock(AbstractNavigationRoute::class);
        $this->cache = $this->createMock(CacheInterface::class);
        $this->eventDispatcher = new EventDispatcher();
        $salesChannel = new SalesChannelEntity();
        $salesChannel->setId(Uuid::randomHex());
        $this->context = new SalesChannelContext(
            new Context(new SalesChannelApiSource(Uuid::randomHex())),
            Uuid::randomHex(),
            null,
            $salesChannel,
            new CurrencyEntity(),
            new CustomerGroupEntity(),
            new TaxCollection(),
            new PaymentMethodEntity(),
            
public function testDebugIsOnDoesNothing(): void
    {
        $subscriber = new NotFoundSubscriber(
            $this->createMock(ErrorController::class),
            $this->createMock(RequestStack::class),
            $this->createMock(SalesChannelContextServiceInterface::class),
            true,
            $this->createMock(CacheInterface::class),
            $this->createMock(AbstractCacheTracer::class),
            $this->createMock(EntityCacheKeyGenerator::class),
            $this->createMock(CacheInvalidator::class),
            new EventDispatcher()
        );

        $event = new ExceptionEvent(
            $this->createMock(Kernel::class),
            new Request(),
            0,
            new \Exception()
        );
        $subscriber->onError($event);

        static::assertNull($event->getResponse());
    }

    use IntegrationTestBehaviour;
    use SalesChannelApiTestBehaviour;

    private Connection $connection;

    private SalesChannelContextPersister $contextPersister;

    protected function setUp(): void
    {
        $this->connection = $this->getContainer()->get(Connection::class);
        $eventDispatcher = new EventDispatcher();
        $this->contextPersister = new SalesChannelContextPersister($this->connection, $eventDispatcher$this->getContainer()->get(CartPersister::class));
    }

    public function testLoad(): void
    {
        $token = Random::getAlphanumericString(32);
        $expected = [
            'key' => 'value',
            'token' => $token,
            'expired' => false,
        ];

        
$this->indexer->method('getIterator')->willReturn($query);

        $client = $this->createMock(Client::class);
        $indices = $this->createMock(IndicesNamespace::class);
        $indices
            ->expects(static::exactly(2))
            ->method('existsAlias')
            ->with(['name' => 'sw-admin-promotion-listing']);

        $client->method('indices')->willReturn($indices);

        $eventDispatcher = new EventDispatcher();
        $queue = $this->createMock(MessageBusInterface::class);
        $connection = $this->createMock(Connection::class);
        $connection->method('fetchAllKeyValue')->willReturn(['sw-admin-promotion-listing' => 'sw-admin-promotion-listing_12345']);

        $searchHelper = new AdminElasticsearchHelper(true, false, 'sw-admin');
        $index = new AdminSearchRegistry(
            ['promotion' => $this->indexer],
            $connection,
            $queue,
            $eventDispatcher,
            $client,
            

    public function testRequestEvent(): void
    {
        $request = new Request();
        $request->attributes->set('_route', 'frontend.home.page');

        $event = new RequestEvent($this->createMock(Kernel::class)$request, HttpKernelInterface::MAIN_REQUEST);

        $listener = $this->getMockBuilder(CallableClass::class)->getMock();
        $listener->expects(static::once())->method('__invoke');

        $dispatcher = new EventDispatcher();
        $dispatcher->addListener('frontend.home.page.request', $listener);

        $subscriber = new RouteEventSubscriber($dispatcher);
        $subscriber->request($event);
    }

    public function testResponseEvent(): void
    {
        $request = new Request();
        $request->attributes->set('_route', 'frontend.home.page');

        
private CachedCountryRoute $cachedRoute;

    private SalesChannelContext $context;

    private CountryRouteResponse $response;

    protected function setUp(): void
    {
        $this->decorated = $this->createMock(AbstractCountryRoute::class);
        $this->cache = $this->createMock(CacheInterface::class);
        $this->eventDispatcher = new EventDispatcher();
        $salesChannel = new SalesChannelEntity();
        $salesChannel->setId(Uuid::randomHex());
        $this->context = new SalesChannelContext(
            new Context(new SalesChannelApiSource(Uuid::randomHex())),
            Uuid::randomHex(),
            null,
            $salesChannel,
            new CurrencyEntity(),
            new CustomerGroupEntity(),
            new TaxCollection(),
            new PaymentMethodEntity(),
            
$this->helper,
            $this->registry,
            $this->indexCreator,
            $this->iteratorFactory,
            $this->client,
            $logger,
            $this->currencyRepository,
            $this->languageRepository,
            1,
            $this->bus,
            $this->newEsIndexer,
            new ElasticsearchLanguageProvider($this->languageRepository, new EventDispatcher())
        );
    }

    /** * @return AbstractElasticsearchDefinition&MockObject */
    private function createDefinition(string $name): AbstractElasticsearchDefinition
    {
        $es = $this->createMock(AbstractElasticsearchDefinition::class);

        $definition = $this->createMock(EntityDefinition::class);
        
private EventDispatcher $eventDispatcher;

    private CachedSalutationRoute $cachedRoute;

    private SalesChannelContext $context;

    protected function setUp(): void
    {
        $this->decorated = $this->createMock(AbstractSalutationRoute::class);
        $this->cache = $this->createMock(CacheInterface::class);
        $this->eventDispatcher = new EventDispatcher();
        $this->context = new SalesChannelContext(
            new Context(new SalesChannelApiSource(Uuid::randomHex())),
            Uuid::randomHex(),
            null,
            new SalesChannelEntity(),
            new CurrencyEntity(),
            new CustomerGroupEntity(),
            new TaxCollection(),
            new PaymentMethodEntity(),
            new ShippingMethodEntity(),
            new ShippingLocation(new CountryEntity(), null, null),
            
private CachedProductSearchRoute $cachedRoute;

    private SalesChannelContext $context;

    private ProductSearchRouteResponse $response;

    protected function setUp(): void
    {
        $this->decorated = $this->createMock(AbstractProductSearchRoute::class);
        $this->cache = $this->createMock(CacheInterface::class);
        $this->eventDispatcher = new EventDispatcher();
        $salesChannel = new SalesChannelEntity();
        $salesChannel->setId(Uuid::randomHex());
        $this->context = new SalesChannelContext(
            new Context(new SalesChannelApiSource(Uuid::randomHex())),
            Uuid::randomHex(),
            null,
            $salesChannel,
            new CurrencyEntity(),
            new CustomerGroupEntity(),
            new TaxCollection(),
            new PaymentMethodEntity(),
            


        static::assertSame($expected, CacheResponseSubscriber::getSubscribedEvents());
    }

    public function testNoHeadersAreSetIfCacheIsDisabled(): void
    {
        $subscriber = new CacheResponseSubscriber(
            $this->createMock(CartService::class),
            100,
            false,
            new MaintenanceModeResolver(new RequestStack()new CoreMaintenanceModeResolver(new EventDispatcher())),
            false,
            null,
            null
        );

        $customer = new CustomerEntity();
        $salesChannelContext = $this->createMock(SalesChannelContext::class);
        $salesChannelContext->method('getCustomer')->willReturn($customer);

        $request = new Request();
        $request->attributes->set(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT, $salesChannelContext);

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