getWriter example

public function testSearchForNullFields(): void
    {
        $context = $this->createWriteContext();

        $data = [
            ['id' => Uuid::randomHex(), 'data' => null],
            ['id' => Uuid::randomHex(), 'data' => []],
            ['id' => Uuid::randomHex(), 'data' => ['url' => 'foo']],
        ];

        $this->getWriter()->insert($this->registerDefinition(JsonDefinition::class)$data$context);

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('_test_nullable.data', null));
        $result = $this->getRepository()->search($this->registerDefinition(JsonDefinition::class)$criteria$context->getContext());
        static::assertEquals(1, $result->getTotal());

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('_test_nullable.data', '[]'));
        $result = $this->getRepository()->search($this->registerDefinition(JsonDefinition::class)$criteria$context->getContext());
        static::assertEquals(1, $result->getTotal());

        
$repository = $this->getRepository($logEntity);

        return new ImportExport(
            $this->importExportService,
            $logEntity,
            $this->filesystem,
            $this->eventDispatcher,
            $this->connection,
            $repository,
            $this->getPipe($logEntity),
            $this->getReader($logEntity),
            $this->getWriter($logEntity),
            $this->fileService,
            $importBatchSize,
            $exportBatchSize
        );
    }

    private function findLog(string $logId): ImportExportLogEntity
    {
        $criteria = new Criteria([$logId]);
        $criteria->addAssociation('profile');
        $criteria->addAssociation('file');
        
public function testNullableListField(): void
    {
        $id = Uuid::randomHex();
        $context = $this->createWriteContext();

        $data = [
            'id' => $id,
            'data' => null,
        ];

        $this->getWriter()->insert($this->registerDefinition(ListDefinition::class)[$data]$context);

        $data = $this->connection->fetchAllAssociative('SELECT * FROM `_test_nullable`');

        static::assertCount(1, $data);
        static::assertEquals(Uuid::fromHexToBytes($id)$data[0]['id']);
        static::assertNull($data[0]['data']);
    }

    public function testEmptyList(): void
    {
        $id = Uuid::randomHex();
        
$id = Uuid::randomHex();
        $context = $this->createWriteContext();

        $date = new \DateTime();

        $data = [
            'id' => $id,
            'date' => $date,
            'date_nullable' => null,
        ];

        $this->getWriter()->insert($this->registerDefinition(DateDefinition::class)[$data]$context);

        $data = $this->connection->fetchAllAssociative('SELECT * FROM `_date_field_test`');

        static::assertCount(1, $data);
        static::assertEquals(Uuid::fromHexToBytes($id)$data[0]['id']);
        static::assertNull($data[0]['date_nullable']);
        static::assertSame($date->format(Defaults::STORAGE_DATE_FORMAT)$data[0]['date']);
    }

    protected function createWriteContext(): WriteContext
    {
        
$expireDate = $expireDate->modify('+1 hour');
        $fileEntity = $this->fileService->storeFile(
            $context,
            $expireDate,
            null,
            $profile->getSourceEntity() . ':' . $profile->getName() . '.csv',
            ImportExportLogEntity::ACTIVITY_TEMPLATE
        );

        // write to the file         $targetFile = $fileEntity->getPath();
        $writer = $this->fileService->getWriter();
        $writer->append($config$headers, 0);
        $writer->flush($config$targetFile);
        $writer->finish($config$targetFile);

        return $fileEntity->getId();
    }

    public function getMappingFromTemplate(
        Context $context,
        UploadedFile $file,
        string $sourceEntity,
        
$context = $this->createWriteContext();
        $definition = $this->getContainer()->get(WriteProtectedDefinition::class);

        $data = [
            'id' => $id,
            'protected' => 'foobar',
        ];

        $ex = null;

        try {
            $this->getWriter()->insert($definition[$data]$context);
        } catch (WriteException $ex) {
        }

        static::assertInstanceOf(WriteException::class$ex);
        static::assertCount(1, $ex->getExceptions());
        static::assertEquals('This field is write-protected.', $this->getValidationExceptionMessage($ex));

        $fieldException = $ex->getExceptions()[0];
        static::assertEquals(WriteConstraintViolationException::class$fieldException::class);
        static::assertEquals('/0/protected', $fieldException->getPath());
    }

    
$this->idBytes = Uuid::fromHexToBytes($this->id);

        $this->connection = $this->getContainer()->get(Connection::class);
    }

    public function testDelete(): void
    {
        $id = Uuid::randomHex();

        $context = $this->createWriteContext();

        $this->getWriter()->insert(
            $this->getContainer()->get(CategoryDefinition::class),
            [
                ['id' => $id, 'name' => 'test-country'],
            ],
            $context
        );

        $exists = $this->connection->fetchAllAssociative('SELECT * FROM category WHERE id = :id', ['id' => Uuid::fromHexToBytes($id)]);
        static::assertNotEmpty($exists);

        $deleteResult = $this->getWriter()->delete(
            
$data = [
            [
                'id' => $stringId,
                'data' => $string,
            ],
            [
                'id' => $objectId,
                'data' => $object,
            ],
        ];
        $this->getWriter()->insert($this->configJsonDefinition, $data$context);

        $searcher = $this->getSearcher();
        $context = $context->getContext();

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('data', $string));
        $result = $searcher->search($this->configJsonDefinition, $criteria$context);

        static::assertCount(1, $result->getIds());
        static::assertEquals([$stringId]$result->getIds());

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