feat: dummy replacement pdf upload for environments other than prod

This commit is contained in:
Björn Fromme
2026-03-15 12:42:28 +01:00
parent 3b99757a08
commit 8988ae7620
12 changed files with 78 additions and 16 deletions
@@ -12,6 +12,7 @@ use App\Event\DocumentConfirmedEvent;
use App\EventListener\DatevEmailSubscriber;
use App\Model\EmailPathAttachmentDto;
use App\Service\Upload\UploadHandler;
use Flagception\Manager\FeatureManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
@@ -21,6 +22,7 @@ class DatevEmailSubscriberTest extends TestCase
private Mailer&MockObject $mailer;
private UploadHandler&MockObject $uploadHandler;
private LoggerInterface&MockObject $logger;
private FeatureManagerInterface&MockObject $featureManager;
private DatevEmailSubscriber $subscriber;
protected function setUp(): void
@@ -28,6 +30,8 @@ class DatevEmailSubscriberTest extends TestCase
$this->mailer = $this->createMock(Mailer::class);
$this->uploadHandler = $this->createMock(UploadHandler::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->featureManager = $this->createMock(FeatureManagerInterface::class);
$this->featureManager->method('isActive')->with('datev_email')->willReturn(true);
$this->subscriber = new DatevEmailSubscriber(
$this->mailer,
@@ -35,6 +39,7 @@ class DatevEmailSubscriberTest extends TestCase
$this->logger,
'[email protected]',
'[email protected]',
$this->featureManager,
);
}
@@ -118,7 +123,7 @@ class DatevEmailSubscriberTest extends TestCase
$nonExistentPath = '/tmp/non_existent_file_'.uniqid().'.pdf';
$this->uploadHandler
->method('getUploadFilepath')
->method('getResolvedUploadFilepath')
->with($document)
->willReturn($nonExistentPath);
@@ -160,7 +165,7 @@ class DatevEmailSubscriberTest extends TestCase
try {
$this->uploadHandler
->expects($this->once())
->method('getUploadFilepath')
->method('getResolvedUploadFilepath')
->with($document)
->willReturn($tmpFile);
+1
View File
@@ -0,0 +1 @@
upload.orig.pdf
+8 -1
View File
@@ -14,6 +14,8 @@ use App\Entity\Upload;
use App\Service\Pdf\InvoiceApprover;
use App\Service\Pdf\InvoiceRenderer;
use App\Service\Pdf\Pdf;
use App\Service\Upload\UploadHandler;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Contracts\Translation\TranslatorInterface;
@@ -25,6 +27,7 @@ class InvoiceApproverTest extends WebTestCase
private string $pdfPath;
private string $origPath;
private Filesystem $filesystem;
private UploadHandler&MockObject $uploadHandler;
protected function setUp(): void
{
@@ -35,6 +38,7 @@ class InvoiceApproverTest extends WebTestCase
$this->pdfPath = $this->invoiceDir.'/test_approver_backup.pdf';
$this->origPath = $this->invoiceDir.'/test_approver_backup.orig.pdf';
$this->filesystem = new Filesystem();
$this->uploadHandler = $this->createMock(UploadHandler::class);
$this->filesystem->mkdir($this->invoiceDir);
}
@@ -80,7 +84,7 @@ class InvoiceApproverTest extends WebTestCase
$translator = $this->createMock(TranslatorInterface::class);
/** @var TranslatorInterface $translator */
return new InvoiceApprover($translator, ['project_dir' => $this->projectDir]);
return new InvoiceApprover($translator, ['project_dir' => $this->projectDir], $this->uploadHandler);
}
private function createDispositionWithInvoicePdf(): Disposition
@@ -130,6 +134,9 @@ class InvoiceApproverTest extends WebTestCase
;
$disposition->addDocument($invoice);
$this->uploadHandler->method('getResolvedUploadFilepath')->with($invoice)->willReturn($this->pdfPath);
$this->uploadHandler->method('getUploadFilepath')->with($invoice)->willReturn($this->pdfPath);
return $disposition;
}
}
+7 -1
View File
@@ -16,6 +16,7 @@ use App\Entity\User;
use App\Service\Pdf\InvoiceApprover;
use App\Service\Pdf\InvoiceRenderer;
use App\Service\Pdf\Pdf;
use App\Service\Upload\UploadHandler;
use Carbon\CarbonPeriod;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Contracts\Translation\TranslatorInterface;
@@ -108,8 +109,13 @@ class InvoiceRendererTest extends WebTestCase
;
$disposition->addDocument($invoice);
$invoicePath = $projectDir.'/uploads/invoice/a/abcdef0123456789.pdf';
$uploadHandler = $this->createMock(UploadHandler::class);
$uploadHandler->method('getResolvedUploadFilepath')->with($invoice)->willReturn($invoicePath);
$uploadHandler->method('getUploadFilepath')->with($invoice)->willReturn($invoicePath);
/** @var TranslatorInterface $translator */
$approver = new InvoiceApprover($translator, ['project_dir' => $projectDir]);
$approver = new InvoiceApprover($translator, ['project_dir' => $projectDir], $uploadHandler);
$pdf = $approver->render($disposition);
$this->assertInstanceOf(Pdf::class, $pdf);
}