getCustomEvents example

private readonly EntityRepository $flowEventsRepository,
        private readonly Connection $connection
    ) {
    }

    public function updateEvents(Event $flowEvent, string $appId, Context $context, string $defaultLocale): void
    {
        $existingFlowEvents = $this->connection->fetchAllKeyValue('SELECT name, LOWER(HEX(id)) FROM app_flow_event WHERE app_id = :appId;', [
            'appId' => Uuid::fromHexToBytes($appId),
        ]);

        $flowEvents = $flowEvent->getCustomEvents()?->getCustomEvents() ?? [];
        $upserts = [];
        foreach ($flowEvents as $event) {
            $payload = array_merge([
                'appId' => $appId,
            ]$event->toArray($defaultLocale));

            $existing = $existingFlowEvents[$event->getName()] ?? null;
            if ($existing) {
                $payload['id'] = $existing;
                unset($existingFlowEvents[$event->getName()]);
            }

            
use PHPUnit\Framework\TestCase;
use Shopware\Core\Framework\App\Flow\Event\Event;

/** * @internal */
class CustomEventsTest extends TestCase
{
    public function testFromXml(): void
    {
        $flowEvents = Event::createFromXmlFile(__DIR__ . '/../_fixtures/valid/flowEventWithFlowEvents.xml');
        static::assertNotNull($flowEvents->getCustomEvents());
        static::assertCount(1, $flowEvents->getCustomEvents()->getCustomEvents());
    }
}
/** * @internal * * @covers \Shopware\Core\Framework\App\Flow\Event\Event */
class FlowEventTest extends TestCase
{
    public function testCreateFromXmlFile(): void
    {
        $xmlFile = \dirname(__FILE__, 3) . '/_fixtures/Resources/flow.xml';
        $result = Event::createFromXmlFile($xmlFile);
        static::assertNotNull($result->getCustomEvents());
        static::assertNotEmpty($result->getCustomEvents()->getCustomEvents());
        static::assertDirectoryExists($result->getPath());
    }

    public function testCreateFromXmlFileFaild(): void
    {
        static::expectException(XmlParsingException::class);
        $xmlFile = \dirname(__FILE__, 3) . '/_fixtures/flow-1-0.xml';
        Event::createFromXmlFile($xmlFile);
    }
}
/** * @internal */
class FlowEventTest extends TestCase
{
    public function testCreateFromXmlWithFlowEvent(): void
    {
        $flowEventsFile = '/_fixtures/valid/flowEventWithFlowEvents.xml';
        $flowEvents = Event::createFromXmlFile(__DIR__ . $flowEventsFile);

        static::assertEquals(__DIR__ . '/_fixtures/valid', $flowEvents->getPath());
        static::assertNotNull($flowEvents->getCustomEvents());
        static::assertCount(1, $flowEvents->getCustomEvents()->getCustomEvents());
    }

    public function testCreateFromXmlMissingFlowEvent(): void
    {
        static::expectException(XmlParsingException::class);
        static::expectExceptionMessage('[ERROR 1871] Element \'flow-events\': Missing child element(s). Expected is ( flow-event ).');
        $flowEventsFile = '/_fixtures/invalid/flowEventWithoutFlowEvents.xml';
        Event::createFromXmlFile(__DIR__ . $flowEventsFile);
    }

    
use Shopware\Core\Framework\App\Flow\Event\Event;

/** * @internal */
class CustomEventTest extends TestCase
{
    public function testFromXml(): void
    {
        $flowEvents = Event::createFromXmlFile(__DIR__ . '/../_fixtures/valid/flowEventWithFlowEvents.xml');

        static::assertNotNull($flowEvents->getCustomEvents());
        static::assertCount(1, $flowEvents->getCustomEvents()->getCustomEvents());

        $firstEvent = $flowEvents->getCustomEvents()->getCustomEvents()[0];
        static::assertNotNull($firstEvent->getName());

        static::assertEquals('checkout.order.place.custom', $firstEvent->getName());
        static::assertEquals(['orderAware', 'customerAware']$firstEvent->getAware());
    }
}
$appEntity = new AppEntity();
        $appEntity->setPath('../_fixtures/');

        $expected = [
            'name' => 'swag.before.open_the_doors',
            'aware' => ['customerAware'],
        ];

        $events = $appLoader->getFlowEvents($appEntity);
        static::assertNotNull($events);
        static::assertNotNull($events->getCustomEvents());
        $customEvents = $events->getCustomEvents();
        $events = $customEvents->getCustomEvents();
        static::assertEquals($expected$events[0]->toArray('en-GB'));
    }

    public function testGetFlowEventsWithFileNotExist(): void
    {
        $appLoader = new AppLoader(
            __DIR__,
            __DIR__,
            new ConfigReader()
        );
Home | Imprint | This part of the site doesn't use cookies.