feat: voucher purchase flow

This commit is contained in:
fromme committed 2026-10-01 15:03:27 +02:00
1 parent a628e96d06
commit f3dd122678
70 files changed
+3672 -122

No files matched your search

@@ -0,0 +1,107 @@
<?php
declare(strict_types=1);
namespace App\Tests\BusProNet\DataProcessor;
use App\BusProNet\Constants;
use App\BusProNet\DataProcessor\VoucherSalePayloadBuilder;
use App\BusProNet\Model\VoucherPaymentMethod;
use App\BusProNet\Model\VoucherTemplate;
use App\Form\Model\VoucherPurchaseDto;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
class VoucherSalePayloadBuilderTest extends TestCase
{
/**
* The shape the test system accepted with <buchung>möglich</buchung> on 2026-10-01.
*/
public function testTheSalePayloadMatchesTheProbedRequest(): void
{
$payload = (new VoucherSalePayloadBuilder())->buildSalePayload($this->createDto(), Constants::BOOKING_TYPE_INQUIRY);
$xml = (new XmlEncoder())->encode(
['satz' => ['@typ' => 'GUTSCHEINBUCHUNG']] + $payload,
'xml',
[XmlEncoder::ROOT_NODE_NAME => 'anfrage', XmlEncoder::ENCODING => 'UTF-8'],
);
self::assertStringContainsString(
'<satz typ="GUTSCHEINBUCHUNG"/><buchungsart>Anfrage</buchungsart><gutscheinart>K</gutscheinart>'
.'<idgutscheinvorlage>3</idgutscheinvorlage><kaeufer>Probe Kaeufer</kaeufer><empfaenger>Probe Empfaenger</empfaenger>'
.'<kaufpreis>25</kaufpreis><text></text>'
.'<rechnungsempfänger><name>Probe</name><vorname>Myep</vorname><anrede>Herr</anrede><titel/><geschlecht></geschlecht><geburtsdatum></geburtsdatum>'
.'<anschrift><strasse>Teststr. 1</strasse><plz>12345</plz><ort>Testort</ort><ortsteil/><land>D</land></anschrift>'
.'<kommunikation><telefonprivat/><email>[email protected]</email><telefonmobil>0170123456</telefonmobil></kommunikation>'
.'</rechnungsempfänger>'
.'<zahlung idzahlungsart="2" bezeichnung="Überweisung" art="UEBERW"/>',
$xml,
);
}
public function testThePurchaseDiffersOnlyInItsSaleType(): void
{
$builder = new VoucherSalePayloadBuilder();
$dto = $this->createDto();
$inquiry = $builder->buildSalePayload($dto, Constants::BOOKING_TYPE_INQUIRY);
$purchase = $builder->buildSalePayload($dto, Constants::BOOKING_TYPE_BOOKING);
self::assertSame('Buchung', $purchase['buchungsart']);
self::assertSame(array_diff_key($inquiry, ['buchungsart' => true]), array_diff_key($purchase, ['buchungsart' => true]));
}
public function testAnEmptyMobileIsLeftOut(): void
{
$dto = $this->createDto();
$dto->mobile = ' ';
$payload = (new VoucherSalePayloadBuilder())->buildSalePayload($dto, Constants::BOOKING_TYPE_INQUIRY);
self::assertArrayNotHasKey('telefonmobil', $payload['rechnungsempfänger']['kommunikation']);
}
public function testThePreviewPayloadCarriesTheVoucherOnly(): void
{
$payload = (new VoucherSalePayloadBuilder())->buildPreviewPayload($this->createDto());
self::assertSame([
'idgutscheinvorlage' => 3,
'kaeufer' => 'Probe Kaeufer',
'empfaenger' => 'Probe Empfaenger',
'kaufpreis' => 25,
'text' => '',
], $payload);
}
public function testASaleWithoutATemplateIsALogicError(): void
{
$dto = $this->createDto();
$dto->template = null;
$this->expectException(\LogicException::class);
(new VoucherSalePayloadBuilder())->buildSalePayload($dto, Constants::BOOKING_TYPE_INQUIRY);
}
private function createDto(): VoucherPurchaseDto
{
$dto = new VoucherPurchaseDto();
$dto->template = new VoucherTemplate(3, 'K', 'Allgemein');
$dto->paymentMethod = new VoucherPaymentMethod(2, 'Überweisung', 'UEBERW');
$dto->from = 'Probe Kaeufer';
$dto->to = 'Probe Empfaenger';
$dto->amount = 25;
$dto->salutation = VoucherPurchaseDto::SALUTATION_MR;
$dto->lastName = 'Probe';
$dto->firstName = 'Myep';
$dto->address->street = 'Teststr. 1';
$dto->address->postCode = '12345';
$dto->address->city = 'Testort';
$dto->email = '[email protected]';
$dto->mobile = '0170123456';
return $dto;
}
}