DocumentGenerationResult example


    public function generate(string $documentType, array $operations, Context $context): DocumentGenerationResult
    {
        $documentTypeId = $this->getDocumentTypeByName($documentType);

        if ($documentTypeId === null) {
            throw new InvalidDocumentRendererException($documentType);
        }

        $rendered = $this->rendererRegistry->render($documentType$operations$contextnew DocumentRendererConfig());

        $result = new DocumentGenerationResult();

        foreach ($rendered->getErrors() as $orderId => $error) {
            $result->addError($orderId$error);
        }

        $records = [];

        $success = $rendered->getSuccess();

        foreach ($operations as $orderId => $operation) {
            try {
                
 $this->context);

        $mergeResult = $documentMerger->merge([$doc1$doc2]$this->context);

        static::assertInstanceOf(RenderedDocument::class$mergeResult);
        static::assertEquals($mergeResult->getContent()$expectedBlob);
    }

    public function testMergeWithoutStaticMedia(): void
    {
        $mockGenerator = $this->getMockBuilder(DocumentGenerator::class)->disableOriginalConstructor()->onlyMethods(['generate'])->getMock();
        $mockGenerator->expects(static::once())->method('generate')->willReturn(new DocumentGenerationResult());

        $documentMerger = new DocumentMerger(
            $this->documentRepository,
            $this->getContainer()->get(MediaService::class),
            $mockGenerator,
            $this->getContainer()->get('pdf.merger'),
        );

        $documentId = Uuid::randomHex();

        $this->documentRepository->create([[
            
Home | Imprint | This part of the site doesn't use cookies.