getCalledListeners example

$this->assertCount(0, $dispatcher->getListeners('foo'));
    }

    public function testGetCalledListeners()
    {
        $tdispatcher = new TraceableEventDispatcher(new EventDispatcher()new Stopwatch());
        $tdispatcher->addListener('foo', function D) {}, 5);

        $listeners = $tdispatcher->getNotCalledListeners();
        $this->assertArrayHasKey('stub', $listeners[0]);
        unset($listeners[0]['stub']);
        $this->assertEquals([]$tdispatcher->getCalledListeners());
        $this->assertEquals([['event' => 'foo', 'pretty' => 'closure', 'priority' => 5]]$listeners);

        $tdispatcher->dispatch(new Event(), 'foo');

        $listeners = $tdispatcher->getCalledListeners();
        $this->assertArrayHasKey('stub', $listeners[0]);
        unset($listeners[0]['stub']);
        $this->assertEquals([['event' => 'foo', 'pretty' => 'closure', 'priority' => 5]]$listeners);
        $this->assertEquals([]$tdispatcher->getNotCalledListeners());
    }

    

        }
    }

    public function lateCollect(): void
    {
        foreach ($this->dispatchers as $name => $dispatcher) {
            if (!$dispatcher instanceof TraceableEventDispatcher) {
                continue;
            }

            $this->setCalledListeners($dispatcher->getCalledListeners($this->currentRequest)$name);
            $this->setNotCalledListeners($dispatcher->getNotCalledListeners($this->currentRequest)$name);
            $this->setOrphanedEvents($dispatcher->getOrphanedEvents($this->currentRequest)$name);
        }

        $this->data = $this->cloneVar($this->data);
    }

    public function getData(): array|Data
    {
        return $this->data;
    }

    

        }
    }

    public function lateCollect(): void
    {
        foreach ($this->dispatchers as $name => $dispatcher) {
            if (!$dispatcher instanceof TraceableEventDispatcher) {
                continue;
            }

            $this->setCalledListeners($dispatcher->getCalledListeners($this->currentRequest)$name);
            $this->setNotCalledListeners($dispatcher->getNotCalledListeners($this->currentRequest)$name);
            $this->setOrphanedEvents($dispatcher->getOrphanedEvents($this->currentRequest)$name);
        }

        $this->data = $this->cloneVar($this->data);
    }

    public function getData(): array|Data
    {
        return $this->data;
    }

    
$this->listener->addSubscriber(new StockSubscriber());

        $filesystem = $this->getContainer()->get('shopware.filesystem.private');

        $productId = Uuid::randomHex();
        $product = $this->getTestProduct($productId);
        $newStock = (int) $product['stock'] + 1;

        $criteria = new Criteria([$productId]);
        $progress = $this->export(Context::createDefaultContext(), ProductDefinition::ENTITY_NAME, $criteria);

        $events = array_column($this->listener->getCalledListeners(), 'event');
        static::assertContains(ImportExportBeforeExportRecordEvent::class$events);

        $logfile = $this->getLogEntity($progress->getLogId())->getFile();
        static::assertInstanceOf(ImportExportFileEntity::class$logfile);
        $csv = $filesystem->read($logfile->getPath());
        static::assertIsString($csv);
        static::assertStringContainsString(";{$newStock};", $csv);
    }

    public function testImportEvents(): void
    {
        
Home | Imprint | This part of the site doesn't use cookies.