getRecord example


        $context = Context::createDefaultContext();

        $this->categoryRepository->upsert($categoriesToWrite$context);

        $event = new ImportExportBeforeImportRecordEvent($record$rownew Config([]['sourceEntity' => ProductDefinition::ENTITY_NAME][])$context);

        $subscriber = new ProductCategoryPathsSubscriber($this->categoryRepository, $this->getContainer()->get(SyncService::class));

        $subscriber->categoryPathsToAssignment($event);

        static::assertSame($assertion$event->getRecord()['categories']);
    }
}


    public function testHandle()
    {
        $handler = new MailerHandler($this->mailer, (new Email())->subject('Alert: %level_name% %message%'));
        $handler->setFormatter(new LineFormatter());
        $this->mailer
            ->expects($this->once())
            ->method('send')
            ->with($this->callback(fn (Email $email) => 'Alert: WARNING message' === $email->getSubject() && null === $email->getHtmlBody()))
        ;
        $handler->handle($this->getRecord(Logger::WARNING, 'message'));
    }

    public function testHandleBatch()
    {
        $handler = new MailerHandler($this->mailer, (new Email())->subject('Alert: %level_name% %message%'));
        $handler->setFormatter(new LineFormatter());
        $this->mailer
            ->expects($this->once())
            ->method('send')
            ->with($this->callback(fn (Email $email) => 'Alert: ERROR error' === $email->getSubject() && null === $email->getHtmlBody()))
        ;
        


            if ($categoryId !== null) {
                $result[] = ['id' => $categoryId];
            }
        }

        if (!empty($newCategoriesPayload)) {
            $this->createNewCategories($newCategoriesPayload);
        }

        $record = $event->getRecord();
        $record['categories'] = !empty($record['categories']) ? array_merge($record['categories']$result) : $result;

        $event->setRecord($record);
    }

    public function reset(): void
    {
        $this->categoryIdCache = [];
    }

    /** * @param list<array<string, mixed>> $payload */
$processor = new DebugProcessor();
        $processor($record);

        $records = $processor->getLogs();
        self::assertCount(1, $records);
        self::assertSame('2019-01-01T00:01:00.000+00:00', $records[0]['timestamp_rfc3339']);
    }

    public function testDebugProcessor()
    {
        $processor = new DebugProcessor();
        $processor(self::getRecord());
        $processor(self::getRecord(Logger::ERROR));

        $this->assertCount(2, $processor->getLogs());
        $this->assertSame(1, $processor->countErrors());
    }

    public function testDebugProcessorWithoutLogs()
    {
        $processor = new DebugProcessor();

        $this->assertCount(0, $processor->getLogs());
        
public function onExport(ImportExportBeforeExportRecordEvent $event): void
    {
        if ($event->getConfig()->get('sourceEntity') !== 'product') {
            return;
        }

        $keys = $event->getConfig()->getMapping()->getKeys();
        if (!\in_array('stock', $keys, true)) {
            return;
        }

        $record = $event->getRecord();
        $record['stock'] = $record['stock'] + 1;
        $event->setRecord($record);
    }
}
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;

class WebProcessorTest extends TestCase
{
    public function testUsesRequestServerData()
    {
        [$event$server] = $this->createRequestEvent();

        $processor = new WebProcessor();
        $processor->onKernelRequest($event);
        $record = $processor($this->getRecord());

        $this->assertCount(5, $record['extra']);
        $this->assertEquals($server['REQUEST_URI']$record['extra']['url']);
        $this->assertEquals($server['REMOTE_ADDR']$record['extra']['ip']);
        $this->assertEquals($server['REQUEST_METHOD']$record['extra']['http_method']);
        $this->assertEquals($server['SERVER_NAME']$record['extra']['server']);
        $this->assertEquals($server['HTTP_REFERER']$record['extra']['referrer']);
    }

    public function testUseRequestClientIp()
    {
        
throw $record['_error'];
                }

                // ensure that the raw csv row has all the fields, which are marked as required by the user.                 $this->ensureUserRequiredFields($row$config);

                $record = $this->ensurePrimaryKeys($record);

                $event = new ImportExportBeforeImportRecordEvent($record$row$config$context);
                $this->eventDispatcher->dispatch($event);

                $record = $event->getRecord();

                if ($createEntities === true && $updateEntities === false) {
                    $result = $this->repository->create([$record]$context);
                } elseif ($createEntities === false && $updateEntities === true) {
                    $result = $this->repository->update([$record]$context);
                } else {
                    // expect that both create and update are true -> upsert                     // both false isn't possible via admin (but still results in an upsert)                     $result = $this->repository->upsert([$record]$context);
                }

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