KeyMappingPipe example

'url' => 'https://shopware.test/foo/bar/media.png',
            'private' => false,
            'mediaType' => 'image/png',
            'translations' => [
                'DEFAULT' => $mediaTranslations,
            ],
        ];

        $mapping = $this->getDefaultMapping(MediaDefinition::ENTITY_NAME);

        $config = new Config($mapping[][]);
        $mappingPipe = new KeyMappingPipe($mapping, true);
        $pipeInResult = $mappingPipe->in($config$media);
        static::assertInstanceOf(\Traversable::class$pipeInResult);
        $mappedMedia = iterator_to_array($pipeInResult);

        static::assertSame($media['id']$mappedMedia['id']);
        static::assertSame($media['mediaFolderId']$mappedMedia['folder_id']);
        static::assertSame($media['url']$mappedMedia['url']);
        static::assertSame($media['private']$mappedMedia['private']);
        static::assertSame($media['mediaType']$mappedMedia['type']);

        static::assertSame($mediaTranslations['alt']$mappedMedia['alt']);
        
public function create(ImportExportLogEntity $logEntity): AbstractPipe
    {
        $pipe = new ChainPipe([
            new EntityPipe(
                $this->definitionInstanceRegistry,
                $this->serializerRegistry,
                null,
                null,
                $this->primaryKeyResolver
            ),
            new KeyMappingPipe(),
        ]);

        return $pipe;
    }

    public function supports(ImportExportLogEntity $logEntity): bool
    {
        return true;
    }
}
/** * @internal * * @covers \Shopware\Core\Content\ImportExport\Processing\Pipe\KeyMappingPipe */
#[Package('system-settings')] class KeyMappingPipeTest extends TestCase
{
    public function testEmptyMapping(): void
    {
        $mapping = [];
        $keyMappingPipe = new KeyMappingPipe($mapping, true);

        $config = new Config($mapping[][]);
        $pipeInResult = $keyMappingPipe->in($config['foo' => 'bar']);
        static::assertInstanceOf(\Traversable::class$pipeInResult);
        $actualOutput = iterator_to_array($pipeInResult);
        static::assertEmpty($actualOutput);

        $pipeOutResult = $keyMappingPipe->out($config['foo' => 'bar']);
        static::assertInstanceOf(\Traversable::class$pipeOutResult);
        $actualOutput = iterator_to_array($pipeOutResult);
        static::assertEmpty($actualOutput);
    }
Home | Imprint | This part of the site doesn't use cookies.