From b99c7d6748743c0d9728af1bb9d83ed95a071c57 Mon Sep 17 00:00:00 2001 From: Markus Thielen Date: Mon, 27 Jan 2025 17:16:27 +0100 Subject: [PATCH] +Payment, PaymentTerm, PaymentService +Custom DTD --- src/CXml/Model/Classification.php | 1 - src/CXml/Model/Payment.php | 22 +++++ src/CXml/Model/PaymentService.php | 31 +++++++ src/CXml/Model/PaymentTerm.php | 18 +++++ src/CXml/Model/Request/OrderRequestHeader.php | 32 +++++++- src/CXml/Validation/DtdValidator.php | 3 + tests/CXmlTest/Handling/HandlerTest.php | 26 +++++- .../Handling/fixtures/order_request.xml | 80 +++++++++++++++++++ tests/metadata/cxml/dtd/1.2.050/Custom.dtd | 10 +++ 9 files changed, 220 insertions(+), 3 deletions(-) create mode 100644 src/CXml/Model/Payment.php create mode 100644 src/CXml/Model/PaymentService.php create mode 100644 src/CXml/Model/PaymentTerm.php create mode 100644 tests/CXmlTest/Handling/fixtures/order_request.xml create mode 100644 tests/metadata/cxml/dtd/1.2.050/Custom.dtd diff --git a/src/CXml/Model/Classification.php b/src/CXml/Model/Classification.php index 8441a8c..8fe79ed 100644 --- a/src/CXml/Model/Classification.php +++ b/src/CXml/Model/Classification.php @@ -6,7 +6,6 @@ use JMS\Serializer\Annotation as Serializer; -#[Serializer\AccessorOrder(order: 'custom', custom: ['value'])] readonly class Classification { public function __construct( diff --git a/src/CXml/Model/Payment.php b/src/CXml/Model/Payment.php new file mode 100644 index 0000000..6acc1c9 --- /dev/null +++ b/src/CXml/Model/Payment.php @@ -0,0 +1,22 @@ +paymentService; + } +} diff --git a/src/CXml/Model/PaymentService.php b/src/CXml/Model/PaymentService.php new file mode 100644 index 0000000..5757275 --- /dev/null +++ b/src/CXml/Model/PaymentService.php @@ -0,0 +1,31 @@ +method; + } + + public function getProvider(): ?string + { + return $this->provider; + } +} diff --git a/src/CXml/Model/PaymentTerm.php b/src/CXml/Model/PaymentTerm.php new file mode 100644 index 0000000..71957cd --- /dev/null +++ b/src/CXml/Model/PaymentTerm.php @@ -0,0 +1,18 @@ +businessPartners[] = $businessPartner; } + + public function getPayment(): ?Payment + { + return $this->payment; + } + + public function setPayment(?Payment $payment): void + { + $this->payment = $payment; + } + + public function getPaymentTerm(): ?PaymentTerm + { + return $this->paymentTerm; + } + + public function setPaymentTerm(?PaymentTerm $paymentTerm): void + { + $this->paymentTerm = $paymentTerm; + } } diff --git a/src/CXml/Validation/DtdValidator.php b/src/CXml/Validation/DtdValidator.php index 3802923..261da47 100644 --- a/src/CXml/Validation/DtdValidator.php +++ b/src/CXml/Validation/DtdValidator.php @@ -39,6 +39,9 @@ public function validateAgainstDtd(string $xml): void $old->loadXML($xml); $validateFiles = ['cXML.dtd', 'Fulfill.dtd', 'Quote.dtd']; + if (file_exists($this->pathToCxmlDtds . '/Custom.dtd')) { + $validateFiles[] = 'Custom.dtd'; + } $this->validateAgainstMultipleDtd($validateFiles, $old); diff --git a/tests/CXmlTest/Handling/HandlerTest.php b/tests/CXmlTest/Handling/HandlerTest.php index db51c4b..8872d1f 100644 --- a/tests/CXmlTest/Handling/HandlerTest.php +++ b/tests/CXmlTest/Handling/HandlerTest.php @@ -35,6 +35,11 @@ public static function getEndpointData(): iterable 'QuoteMessage', ]; + yield [ + self::loadFixture('order_request.xml'), + 'OrderRequest', + ]; + // TODO add more cases } @@ -47,7 +52,7 @@ private static function loadFixture(string $filename): ?string public function testEndpoint(string $requestCxml, string $expectedHandlerCalled): void { $serializer = Serializer::create(); - $messageValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); + $messageValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050'); $credentialRepository = new Registry(); $credentialRepository->registerCredential( @@ -90,8 +95,27 @@ public function handle(PayloadInterface $payload, Context $context): ?ResponsePa } }; + $orderRequestHandler = new class($actualHandlerCalled) implements HandlerInterface { + public function __construct(private string &$actualHandlerCalled) + { + } + + public static function getRequestName(): string + { + return 'OrderRequest'; + } + + public function handle(PayloadInterface $payload, Context $context): ?ResponsePayloadInterface + { + $this->actualHandlerCalled = 'OrderRequest'; + + return null; + } + }; + $handlerRegistry = new HandlerRegistry(); $handlerRegistry->register($quoteMessageHandler); + $handlerRegistry->register($orderRequestHandler); $builder = Builder::create(); diff --git a/tests/CXmlTest/Handling/fixtures/order_request.xml b/tests/CXmlTest/Handling/fixtures/order_request.xml new file mode 100644 index 0000000..e03943a --- /dev/null +++ b/tests/CXmlTest/Handling/fixtures/order_request.xml @@ -0,0 +1,80 @@ + + +
+ + + AN00000123 + + + + + AN00000456 + + + + + AN00000123 + Secret!123 + + Suppliers Super Order Processor + +
+ + + + + 10.00 + + +
+ TEST.USA ACME + + ACME + TEST.USA + 22 E 4th Ave + Columbus + OH + 43201-3551 + United States + +49121255566 + +
+
+ +
+ TEST.USA ACME + + ACME + TEST.USA + 22 E 4th Ave + Columbus + OH + 43201-3551 + United States + +
+
+ + + + + + +
+ + + QA-ACME-AUTOTEST + QA-ACME-AUTOTEST + + + + 10.00 + + Testing + EA + QA-ACME-AUTOTEST + + +
+
+
\ No newline at end of file diff --git a/tests/metadata/cxml/dtd/1.2.050/Custom.dtd b/tests/metadata/cxml/dtd/1.2.050/Custom.dtd new file mode 100644 index 0000000..64b182a --- /dev/null +++ b/tests/metadata/cxml/dtd/1.2.050/Custom.dtd @@ -0,0 +1,10 @@ + + + +%elements; + + + \ No newline at end of file