diff --git a/composer.json b/composer.json
index c5941f8..1886822 100644
--- a/composer.json
+++ b/composer.json
@@ -22,5 +22,18 @@
"phpstan/phpstan": "^2.1",
"friendsofphp/php-cs-fixer": "^3.93",
"phpunit/phpunit": "^12.5"
+ },
+ "scripts": {
+ "cs-fix": "php-cs-fixer fix",
+ "cs-check": "php-cs-fixer check",
+ "phpstan": "phpstan",
+ "test": "phpunit",
+ "rector": "./tools/bin/rector",
+ "quality-check": [
+ "@rector",
+ "@cs-check",
+ "@phpstan",
+ "@test"
+ ]
}
}
diff --git a/src/CrossDomainAcknowledgementAndResponse.php b/src/CrossDomainAcknowledgementAndResponse.php
index 30bc560..4ca4bad 100644
--- a/src/CrossDomainAcknowledgementAndResponse.php
+++ b/src/CrossDomainAcknowledgementAndResponse.php
@@ -13,13 +13,11 @@
use TiimePDP\CrossDomainAcknowledgementAndResponse\ReusableAggregateBusinessInformationEntity\AcknowledgementDocumentType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\ReusableAggregateBusinessInformationEntity\ExchangedDocumentContextType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\ReusableAggregateBusinessInformationEntity\ExchangedDocumentType;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
/**
* Cross Domain Acknowledgement and Response message
* UN/EDIFACT D23B standard.
*/
-#[SerializedNamespace(NamespaceUri::RSM)]
#[XmlRoot(name: 'CrossDomainAcknowledgementAndResponse', namespace: NamespaceUri::RSM->value, prefix: 'rsm')]
#[XmlNamespace(
uri: NamespaceUri::RAM->value,
diff --git a/src/QualifiedDataType/AcknowledgementCodeType.php b/src/QualifiedDataType/AcknowledgementCodeType.php
index e53ae0f..6ce2884 100644
--- a/src/QualifiedDataType/AcknowledgementCodeType.php
+++ b/src/QualifiedDataType/AcknowledgementCodeType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Qualified acknowledgement code type.
*/
-#[SerializedNamespace(NamespaceUri::QDT)]
-final readonly class AcknowledgementCodeType implements ValueObjectInterface
+final readonly class AcknowledgementCodeType
{
/**
* Acknowledgement code value.
diff --git a/src/QualifiedDataType/ContactTypeCodeType.php b/src/QualifiedDataType/ContactTypeCodeType.php
index 0dbecdc..1f6f86f 100644
--- a/src/QualifiedDataType/ContactTypeCodeType.php
+++ b/src/QualifiedDataType/ContactTypeCodeType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Qualified contact type code type.
*/
-#[SerializedNamespace(NamespaceUri::QDT)]
-final readonly class ContactTypeCodeType implements ValueObjectInterface
+final readonly class ContactTypeCodeType
{
/**
* Code value.
diff --git a/src/QualifiedDataType/CountryIDType.php b/src/QualifiedDataType/CountryIDType.php
index 678fae2..4099e86 100644
--- a/src/QualifiedDataType/CountryIDType.php
+++ b/src/QualifiedDataType/CountryIDType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Qualified country identifier type (ISO two-letter code).
*/
-#[SerializedNamespace(NamespaceUri::QDT)]
-final readonly class CountryIDType implements ValueObjectInterface
+final readonly class CountryIDType
{
/**
* ISO two-letter country code.
diff --git a/src/QualifiedDataType/DateTimeStringType.php b/src/QualifiedDataType/DateTimeStringType.php
index ca400a6..bfef28a 100644
--- a/src/QualifiedDataType/DateTimeStringType.php
+++ b/src/QualifiedDataType/DateTimeStringType.php
@@ -7,12 +7,8 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
use TiimePDP\CrossDomainAcknowledgementAndResponse\Codelist\TimePointFormatCode;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
-#[SerializedNamespace(NamespaceUri::QDT)]
-final class DateTimeStringType implements ValueObjectInterface
+final class DateTimeStringType
{
/**
* Date time string value.
diff --git a/src/QualifiedDataType/DocumentCodeType.php b/src/QualifiedDataType/DocumentCodeType.php
index 6756a13..377007e 100644
--- a/src/QualifiedDataType/DocumentCodeType.php
+++ b/src/QualifiedDataType/DocumentCodeType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Qualified document code type.
*/
-#[SerializedNamespace(NamespaceUri::QDT)]
-final readonly class DocumentCodeType implements ValueObjectInterface
+final readonly class DocumentCodeType
{
/**
* Code value.
diff --git a/src/QualifiedDataType/DocumentStatusCodeType.php b/src/QualifiedDataType/DocumentStatusCodeType.php
index 6fc581b..61486f9 100644
--- a/src/QualifiedDataType/DocumentStatusCodeType.php
+++ b/src/QualifiedDataType/DocumentStatusCodeType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Qualified document status code type.
*/
-#[SerializedNamespace(NamespaceUri::QDT)]
-final readonly class DocumentStatusCodeType implements ValueObjectInterface
+final readonly class DocumentStatusCodeType
{
/**
* Code value.
diff --git a/src/QualifiedDataType/FormattedDateTimeType.php b/src/QualifiedDataType/FormattedDateTimeType.php
index 9937db6..d1c6164 100644
--- a/src/QualifiedDataType/FormattedDateTimeType.php
+++ b/src/QualifiedDataType/FormattedDateTimeType.php
@@ -6,12 +6,10 @@
use JMS\Serializer\Annotation\XmlElement;
use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
/**
* Qualified formatted date time type.
*/
-#[SerializedNamespace(NamespaceUri::QDT)]
final readonly class FormattedDateTimeType
{
/**
diff --git a/src/QualifiedDataType/LanguageIDType.php b/src/QualifiedDataType/LanguageIDType.php
index 5ea5f10..babcfe3 100644
--- a/src/QualifiedDataType/LanguageIDType.php
+++ b/src/QualifiedDataType/LanguageIDType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Qualified language identifier type (ISO Alpha-2 code).
*/
-#[SerializedNamespace(NamespaceUri::QDT)]
-final readonly class LanguageIDType implements ValueObjectInterface
+final readonly class LanguageIDType
{
/**
* ISO Alpha-2 language code.
diff --git a/src/QualifiedDataType/PartyRoleCodeType.php b/src/QualifiedDataType/PartyRoleCodeType.php
index 4aee7c8..2eb83d2 100644
--- a/src/QualifiedDataType/PartyRoleCodeType.php
+++ b/src/QualifiedDataType/PartyRoleCodeType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Qualified party role code type.
*/
-#[SerializedNamespace(NamespaceUri::QDT)]
-final readonly class PartyRoleCodeType implements ValueObjectInterface
+final readonly class PartyRoleCodeType
{
/**
* Code value.
diff --git a/src/QualifiedDataType/ReferenceCodeType.php b/src/QualifiedDataType/ReferenceCodeType.php
index 24918f3..3c4cf04 100644
--- a/src/QualifiedDataType/ReferenceCodeType.php
+++ b/src/QualifiedDataType/ReferenceCodeType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Qualified reference code type.
*/
-#[SerializedNamespace(NamespaceUri::QDT)]
-final readonly class ReferenceCodeType implements ValueObjectInterface
+final readonly class ReferenceCodeType
{
/**
* Code value.
diff --git a/src/QualifiedDataType/StatusCodeType.php b/src/QualifiedDataType/StatusCodeType.php
index a78f7ee..620e558 100644
--- a/src/QualifiedDataType/StatusCodeType.php
+++ b/src/QualifiedDataType/StatusCodeType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Qualified status code type.
*/
-#[SerializedNamespace(NamespaceUri::QDT)]
-final readonly class StatusCodeType implements ValueObjectInterface
+final readonly class StatusCodeType
{
/**
* Status code value.
diff --git a/src/ReusableAggregateBusinessInformationEntity/AcknowledgementDocumentType.php b/src/ReusableAggregateBusinessInformationEntity/AcknowledgementDocumentType.php
index 3270750..53c4c0c 100644
--- a/src/ReusableAggregateBusinessInformationEntity/AcknowledgementDocumentType.php
+++ b/src/ReusableAggregateBusinessInformationEntity/AcknowledgementDocumentType.php
@@ -11,7 +11,6 @@
use TiimePDP\CrossDomainAcknowledgementAndResponse\QualifiedDataType\AcknowledgementCodeType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\QualifiedDataType\DocumentCodeType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\QualifiedDataType\StatusCodeType;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\CodeType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\DateTimeType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\IDType;
@@ -21,7 +20,6 @@
/**
* Acknowledgement document.
*/
-#[SerializedNamespace(NamespaceUri::RAM)]
final readonly class AcknowledgementDocumentType
{
/**
diff --git a/src/ReusableAggregateBusinessInformationEntity/DocumentCharacteristicType.php b/src/ReusableAggregateBusinessInformationEntity/DocumentCharacteristicType.php
index 520ae6a..f4f868c 100644
--- a/src/ReusableAggregateBusinessInformationEntity/DocumentCharacteristicType.php
+++ b/src/ReusableAggregateBusinessInformationEntity/DocumentCharacteristicType.php
@@ -6,7 +6,6 @@
use JMS\Serializer\Annotation\XmlElement;
use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\AmountType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\CodeType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\DateTimeType;
@@ -21,7 +20,6 @@
/**
* Document characteristic.
*/
-#[SerializedNamespace(NamespaceUri::RAM)]
final readonly class DocumentCharacteristicType
{
/**
diff --git a/src/ReusableAggregateBusinessInformationEntity/DocumentContextParameterType.php b/src/ReusableAggregateBusinessInformationEntity/DocumentContextParameterType.php
index 0a975a0..d0c0712 100644
--- a/src/ReusableAggregateBusinessInformationEntity/DocumentContextParameterType.php
+++ b/src/ReusableAggregateBusinessInformationEntity/DocumentContextParameterType.php
@@ -7,13 +7,11 @@
use JMS\Serializer\Annotation\XmlElement;
use JMS\Serializer\Annotation\XmlRoot;
use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\IDType;
/**
* Document context parameter.
*/
-#[SerializedNamespace(NamespaceUri::RAM)]
#[XmlRoot(namespace: NamespaceUri::RAM->value)]
final readonly class DocumentContextParameterType
{
diff --git a/src/ReusableAggregateBusinessInformationEntity/DocumentStatusType.php b/src/ReusableAggregateBusinessInformationEntity/DocumentStatusType.php
index a390b9c..63184ca 100644
--- a/src/ReusableAggregateBusinessInformationEntity/DocumentStatusType.php
+++ b/src/ReusableAggregateBusinessInformationEntity/DocumentStatusType.php
@@ -7,7 +7,6 @@
use JMS\Serializer\Annotation\XmlElement;
use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
use TiimePDP\CrossDomainAcknowledgementAndResponse\QualifiedDataType\DocumentStatusCodeType;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\CodeType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\DateTimeType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\NumericType;
@@ -16,7 +15,6 @@
/**
* Document status.
*/
-#[SerializedNamespace(NamespaceUri::RAM)]
final readonly class DocumentStatusType
{
/**
diff --git a/src/ReusableAggregateBusinessInformationEntity/ExchangedDocumentContextType.php b/src/ReusableAggregateBusinessInformationEntity/ExchangedDocumentContextType.php
index d7443de..f7b5e45 100644
--- a/src/ReusableAggregateBusinessInformationEntity/ExchangedDocumentContextType.php
+++ b/src/ReusableAggregateBusinessInformationEntity/ExchangedDocumentContextType.php
@@ -6,13 +6,11 @@
use JMS\Serializer\Annotation\XmlElement;
use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\IndicatorType;
/**
* Exchanged document context.
*/
-#[SerializedNamespace(NamespaceUri::RAM)]
final readonly class ExchangedDocumentContextType
{
/**
diff --git a/src/ReusableAggregateBusinessInformationEntity/ExchangedDocumentType.php b/src/ReusableAggregateBusinessInformationEntity/ExchangedDocumentType.php
index e8ebe17..7da5be9 100644
--- a/src/ReusableAggregateBusinessInformationEntity/ExchangedDocumentType.php
+++ b/src/ReusableAggregateBusinessInformationEntity/ExchangedDocumentType.php
@@ -10,7 +10,6 @@
use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
use TiimePDP\CrossDomainAcknowledgementAndResponse\QualifiedDataType\DocumentCodeType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\QualifiedDataType\DocumentStatusCodeType;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\DateTimeType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\IDType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\IndicatorType;
@@ -19,7 +18,6 @@
/**
* Exchanged document.
*/
-#[SerializedNamespace(NamespaceUri::RAM)]
final readonly class ExchangedDocumentType
{
/**
diff --git a/src/ReusableAggregateBusinessInformationEntity/NoteType.php b/src/ReusableAggregateBusinessInformationEntity/NoteType.php
index b356b4c..17fe26c 100644
--- a/src/ReusableAggregateBusinessInformationEntity/NoteType.php
+++ b/src/ReusableAggregateBusinessInformationEntity/NoteType.php
@@ -6,14 +6,12 @@
use JMS\Serializer\Annotation\XmlElement;
use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\CodeType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\TextType;
/**
* Note.
*/
-#[SerializedNamespace(NamespaceUri::RAM)]
final readonly class NoteType
{
/**
diff --git a/src/ReusableAggregateBusinessInformationEntity/ReferencedDocumentType.php b/src/ReusableAggregateBusinessInformationEntity/ReferencedDocumentType.php
index 1bbd302..0a8da64 100644
--- a/src/ReusableAggregateBusinessInformationEntity/ReferencedDocumentType.php
+++ b/src/ReusableAggregateBusinessInformationEntity/ReferencedDocumentType.php
@@ -13,7 +13,6 @@
use TiimePDP\CrossDomainAcknowledgementAndResponse\QualifiedDataType\FormattedDateTimeType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\QualifiedDataType\LanguageIDType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\QualifiedDataType\ReferenceCodeType;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\AmountType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\BinaryObjectType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\CodeType;
@@ -26,7 +25,6 @@
/**
* Document référencé.
*/
-#[SerializedNamespace(NamespaceUri::RAM)]
final readonly class ReferencedDocumentType
{
/**
diff --git a/src/ReusableAggregateBusinessInformationEntity/SpecifiedPeriodType.php b/src/ReusableAggregateBusinessInformationEntity/SpecifiedPeriodType.php
index 9b45f3d..e8afec1 100644
--- a/src/ReusableAggregateBusinessInformationEntity/SpecifiedPeriodType.php
+++ b/src/ReusableAggregateBusinessInformationEntity/SpecifiedPeriodType.php
@@ -4,14 +4,11 @@
namespace TiimePDP\CrossDomainAcknowledgementAndResponse\ReusableAggregateBusinessInformationEntity;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\DateTimeType;
/**
* Specified period.
*/
-#[SerializedNamespace(NamespaceUri::RAM)]
final readonly class SpecifiedPeriodType
{
/**
diff --git a/src/ReusableAggregateBusinessInformationEntity/TradeAddressType.php b/src/ReusableAggregateBusinessInformationEntity/TradeAddressType.php
index c69b7d3..1234aa2 100644
--- a/src/ReusableAggregateBusinessInformationEntity/TradeAddressType.php
+++ b/src/ReusableAggregateBusinessInformationEntity/TradeAddressType.php
@@ -7,7 +7,6 @@
use JMS\Serializer\Annotation\XmlElement;
use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
use TiimePDP\CrossDomainAcknowledgementAndResponse\QualifiedDataType\CountryIDType;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\CodeType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\IDType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\TextType;
@@ -15,7 +14,6 @@
/**
* Trade address.
*/
-#[SerializedNamespace(NamespaceUri::RAM)]
final readonly class TradeAddressType
{
/**
diff --git a/src/ReusableAggregateBusinessInformationEntity/TradeContactType.php b/src/ReusableAggregateBusinessInformationEntity/TradeContactType.php
index b64b2e3..60ca71e 100644
--- a/src/ReusableAggregateBusinessInformationEntity/TradeContactType.php
+++ b/src/ReusableAggregateBusinessInformationEntity/TradeContactType.php
@@ -9,14 +9,12 @@
use JMS\Serializer\Annotation\XmlList;
use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
use TiimePDP\CrossDomainAcknowledgementAndResponse\QualifiedDataType\ContactTypeCodeType;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\IDType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\TextType;
/**
* Trade contact.
*/
-#[SerializedNamespace(NamespaceUri::RAM)]
final readonly class TradeContactType
{
/**
diff --git a/src/ReusableAggregateBusinessInformationEntity/TradePartyType.php b/src/ReusableAggregateBusinessInformationEntity/TradePartyType.php
index aa9e3f1..05086c4 100644
--- a/src/ReusableAggregateBusinessInformationEntity/TradePartyType.php
+++ b/src/ReusableAggregateBusinessInformationEntity/TradePartyType.php
@@ -9,14 +9,12 @@
use JMS\Serializer\Annotation\XmlList;
use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
use TiimePDP\CrossDomainAcknowledgementAndResponse\QualifiedDataType\PartyRoleCodeType;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\IDType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\TextType;
/**
* Trade party.
*/
-#[SerializedNamespace(NamespaceUri::RAM)]
final readonly class TradePartyType
{
/**
diff --git a/src/ReusableAggregateBusinessInformationEntity/UniversalCommunicationType.php b/src/ReusableAggregateBusinessInformationEntity/UniversalCommunicationType.php
index f610aba..0259233 100644
--- a/src/ReusableAggregateBusinessInformationEntity/UniversalCommunicationType.php
+++ b/src/ReusableAggregateBusinessInformationEntity/UniversalCommunicationType.php
@@ -6,14 +6,12 @@
use JMS\Serializer\Annotation\XmlElement;
use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\IDType;
use TiimePDP\CrossDomainAcknowledgementAndResponse\UnqualifiedDataType\TextType;
/**
* Universal communication.
*/
-#[SerializedNamespace(NamespaceUri::RAM)]
final readonly class UniversalCommunicationType
{
/**
diff --git a/src/Serializer/JmsSerializer.php b/src/Serializer/JmsSerializer.php
deleted file mode 100644
index 365137a..0000000
--- a/src/Serializer/JmsSerializer.php
+++ /dev/null
@@ -1,39 +0,0 @@
-serializer = SerializerBuilder::create()
- ->setPropertyNamingStrategy($namingStrategy)
- ->enableEnumSupport()
- ->build();
- }
-
- public function serialize(CrossDomainAcknowledgementAndResponse $cdar): string
- {
- return $this->serializer->serialize($cdar, 'xml');
- }
-
- public function deserialize(string $data): CrossDomainAcknowledgementAndResponse
- {
- /** @var CrossDomainAcknowledgementAndResponse $cdar */
- $cdar = $this->serializer->deserialize($data, CrossDomainAcknowledgementAndResponse::class, 'xml');
-
- return $cdar;
- }
-}
diff --git a/src/Serializer/SerializedNamespace.php b/src/Serializer/SerializedNamespace.php
deleted file mode 100644
index 4d6c3f7..0000000
--- a/src/Serializer/SerializedNamespace.php
+++ /dev/null
@@ -1,18 +0,0 @@
-namespace = $namespace;
- }
-}
diff --git a/src/Serializer/Serializer.php b/src/Serializer/Serializer.php
index 316bada..e1ab513 100644
--- a/src/Serializer/Serializer.php
+++ b/src/Serializer/Serializer.php
@@ -4,217 +4,50 @@
namespace TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer;
+use JMS\Serializer\Naming\CamelCaseNamingStrategy;
+use JMS\Serializer\SerializerBuilder;
use TiimePDP\CrossDomainAcknowledgementAndResponse\CrossDomainAcknowledgementAndResponse;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
-/**
- * UN/EDIFACT D23B Serializer to XML.
- */
final class Serializer
{
- private \DOMDocument $doc;
+ private \JMS\Serializer\Serializer $serializer;
- /**
- * @throws SerializationException
- */
- public function serialize(CrossDomainAcknowledgementAndResponse $cdar, bool $pretty = false): string
+ public function __construct()
{
- $this->doc = new \DOMDocument('1.0', 'UTF-8');
-
- if ($pretty) {
- $this->doc->formatOutput = true;
- $this->doc->preserveWhiteSpace = true;
- }
-
- try {
- $rootElement = $this->serializeObject(
- object: $cdar,
- elementName: 'CrossDomainAcknowledgementAndResponse',
- parentNamespacePrefix: NamespaceUri::RSM->prefix(),
- isRoot: true,
- );
- } catch (\DOMException|\ReflectionException $exception) {
- throw new SerializationException(message: 'Failed to serialize CrossDomainAcknowledgementAndResponse to XML: '.$exception->getMessage(), previous: $exception);
- }
-
- $this->doc->appendChild($rootElement);
-
- $xml = $this->doc->saveXML();
-
- if (false === $xml) {
- throw new SerializationException('Failed to serialize CrossDomainAcknowledgementAndResponse to XML.');
- }
-
- return $xml;
- }
-
- /**
- * Serialize an object to a DOMElement with proper UN/EDIFACT structure.
- *
- * @throws \DOMException|\ReflectionException
- */
- private function serializeObject(
- object $object,
- string $elementName,
- string $parentNamespacePrefix,
- bool $isRoot = false,
- ): \DOMElement {
- $element = $this->doc->createElement($parentNamespacePrefix.':'.$elementName);
-
- $namespaceUri = $this->getNamespaceUriForClass($object);
- $namespacePrefix = $namespaceUri->prefix();
-
- if ($isRoot) {
- foreach (NamespaceUri::cases() as $namespaceUri) {
- $element->setAttributeNS(
- namespace: 'http://www.w3.org/2000/xmlns/',
- qualifiedName: 'xmlns:'.$namespaceUri->prefix(),
- value: $namespaceUri->value,
- );
- }
- }
-
- $reflectionClass = new \ReflectionClass($object);
- $properties = $reflectionClass->getProperties(\ReflectionProperty::IS_PRIVATE);
-
- foreach ($properties as $property) {
- $value = $property->getValue($object);
-
- if (null === $value) {
- continue;
- }
-
- $propertyName = $property->getName();
- $elementNameForProperty = $this->elementNameFromProperty($propertyName);
-
- if (\is_array($value)) {
- foreach ($value as $item) {
- if (null === $item) {
- continue;
- }
-
- $childElement = $this->serializeValue(
- value: $item,
- elementName: $elementNameForProperty,
- namespacePrefix: $namespacePrefix,
- );
- $element->appendChild($childElement);
- }
-
- continue;
- }
-
- $childElement = $this->serializeValue($value, $elementNameForProperty, $namespacePrefix);
- $element->appendChild($childElement);
- }
-
- return $element;
+ $namingStrategy = new CustomPropertyNamingStrategy(
+ new CamelCaseNamingStrategy(separator: '', lowerCase: false)
+ );
+
+ $this->serializer = SerializerBuilder::create()
+ ->setPropertyNamingStrategy($namingStrategy)
+ ->enableEnumSupport()
+ ->build();
}
/**
- * Convert a property name to an element name by capitalizing the first letter.
- */
- private function elementNameFromProperty(string $propertyName): string
- {
- if ('' === $propertyName) {
- return $propertyName;
- }
-
- // If the property name is all uppercase, return it as is (e.g., "ID" stays "ID")
- if (\strtoupper($propertyName) === $propertyName) {
- return $propertyName;
- }
-
- return \ucfirst($propertyName);
- }
-
- /**
- * Populate a DOMElement with attributes and text content from a ValueObjectInterface.
- */
- private function populateValueObject(\DOMElement $element, ValueObjectInterface $object): void
- {
- $value = $object->getValue();
- $element->appendChild($this->doc->createTextNode($value));
-
- foreach (\get_class_methods($object) as $method) {
- if (!\str_starts_with($method, 'get') || 'getValue' === $method) {
- continue;
- }
-
- $attributeValue = $object->{$method}();
- if (null === $attributeValue) {
- continue;
- }
-
- $attributeName = \lcfirst(\substr($method, 3));
- if ($attributeValue instanceof \BackedEnum) {
- $element->setAttribute($attributeName, (string) $attributeValue->value);
-
- continue;
- }
-
- if (false === is_scalar($attributeValue)) {
- throw new \RuntimeException(message: 'Cannot serialize non-scalar attribute value for '.$attributeName);
- }
-
- $element->setAttribute($attributeName, (string) $attributeValue);
- }
- }
-
- /**
- * @param object|class-string $object
- *
- * @throws \ReflectionException
+ * @throws SerializationException
*/
- private function getNamespaceUriForClass(object|string $object): NamespaceUri
+ public function serialize(CrossDomainAcknowledgementAndResponse $cdar): string
{
- $reflection = new \ReflectionClass($object);
- $attributes = $reflection->getAttributes(SerializedNamespace::class);
-
- if ([] === $attributes) {
- throw new \RuntimeException('Missing SerializedNamespace attribute on '.$reflection->getName());
+ try {
+ return $this->serializer->serialize($cdar, 'xml');
+ } catch (\Throwable $throwable) {
+ throw new SerializationException(message: 'An error occurred during serialization. Error: '.$throwable->getMessage(), previous: $throwable);
}
-
- /** @var SerializedNamespace $attribute */
- $attribute = $attributes[0]->newInstance();
-
- return $attribute->namespace;
}
/**
- * @throws \DOMException|\ReflectionException
+ * @throws SerializationException
*/
- private function serializeValue(mixed $value, string $elementName, string $namespacePrefix): \DOMElement
+ public function deserialize(string $data): CrossDomainAcknowledgementAndResponse
{
- if ($value instanceof ValueObjectInterface) {
- $child = $this->doc->createElement($namespacePrefix.':'.$elementName);
- $this->populateValueObject($child, $value);
-
- return $child;
- }
-
- if ($value instanceof \BackedEnum) {
- $child = $this->doc->createElement($namespacePrefix.':'.$elementName);
- $child->appendChild($this->doc->createTextNode((string) $value->value));
-
- return $child;
- }
+ try {
+ /** @var CrossDomainAcknowledgementAndResponse $cdar */
+ $cdar = $this->serializer->deserialize($data, CrossDomainAcknowledgementAndResponse::class, 'xml');
- if (\is_object($value)) {
- return $this->serializeObject($value, $elementName, $namespacePrefix);
+ return $cdar;
+ } catch (\Throwable $throwable) {
+ throw new SerializationException(message: 'An error occurred during deserialization. Error: '.$throwable->getMessage(), previous: $throwable);
}
-
- $prefixedName = $namespacePrefix.':'.$elementName;
- $element = $this->doc->createElement($prefixedName);
-
- $textValue = match (true) {
- \is_bool($value) => $value ? 'true' : 'false',
- default => throw new \RuntimeException('Unsupported value type for serialization: '.\gettype($value)),
- };
-
- $element->appendChild($this->doc->createTextNode($textValue));
-
- return $element;
}
}
diff --git a/src/UnqualifiedDataType/AmountType.php b/src/UnqualifiedDataType/AmountType.php
index 795c16c..8df9f7e 100644
--- a/src/UnqualifiedDataType/AmountType.php
+++ b/src/UnqualifiedDataType/AmountType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Unqualified amount data type.
*/
-#[SerializedNamespace(NamespaceUri::UDT)]
-final readonly class AmountType implements ValueObjectInterface
+final readonly class AmountType
{
/**
* Amount value.
diff --git a/src/UnqualifiedDataType/BinaryObjectType.php b/src/UnqualifiedDataType/BinaryObjectType.php
index 87ae953..1ec37da 100644
--- a/src/UnqualifiedDataType/BinaryObjectType.php
+++ b/src/UnqualifiedDataType/BinaryObjectType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Unqualified binary object data type.
*/
-#[SerializedNamespace(NamespaceUri::UDT)]
-final readonly class BinaryObjectType implements ValueObjectInterface
+final readonly class BinaryObjectType
{
/**
* Binary object value encoded in base64.
diff --git a/src/UnqualifiedDataType/CodeType.php b/src/UnqualifiedDataType/CodeType.php
index 82277da..2b57832 100644
--- a/src/UnqualifiedDataType/CodeType.php
+++ b/src/UnqualifiedDataType/CodeType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Unqualified code data type.
*/
-#[SerializedNamespace(NamespaceUri::UDT)]
-final readonly class CodeType implements ValueObjectInterface
+final readonly class CodeType
{
/**
* Code value.
diff --git a/src/UnqualifiedDataType/DateTimeStringType.php b/src/UnqualifiedDataType/DateTimeStringType.php
index 3f9864d..7b51788 100644
--- a/src/UnqualifiedDataType/DateTimeStringType.php
+++ b/src/UnqualifiedDataType/DateTimeStringType.php
@@ -6,12 +6,8 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
-#[SerializedNamespace(NamespaceUri::UDT)]
-final class DateTimeStringType implements ValueObjectInterface
+final class DateTimeStringType
{
/**
* Date time string value.
diff --git a/src/UnqualifiedDataType/DateTimeType.php b/src/UnqualifiedDataType/DateTimeType.php
index 8779ad0..d91e595 100644
--- a/src/UnqualifiedDataType/DateTimeType.php
+++ b/src/UnqualifiedDataType/DateTimeType.php
@@ -7,12 +7,10 @@
use JMS\Serializer\Annotation\Type;
use JMS\Serializer\Annotation\XmlElement;
use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
/**
* Unqualified date time data type.
*/
-#[SerializedNamespace(NamespaceUri::UDT)]
final readonly class DateTimeType
{
/**
diff --git a/src/UnqualifiedDataType/IDType.php b/src/UnqualifiedDataType/IDType.php
index 58d5ae8..a779358 100644
--- a/src/UnqualifiedDataType/IDType.php
+++ b/src/UnqualifiedDataType/IDType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Unqualified identifier data type.
*/
-#[SerializedNamespace(NamespaceUri::UDT)]
-final readonly class IDType implements ValueObjectInterface
+final readonly class IDType
{
/**
* Identifier value.
diff --git a/src/UnqualifiedDataType/IndicatorStringType.php b/src/UnqualifiedDataType/IndicatorStringType.php
index d8a6280..7c852a1 100644
--- a/src/UnqualifiedDataType/IndicatorStringType.php
+++ b/src/UnqualifiedDataType/IndicatorStringType.php
@@ -6,12 +6,8 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
-#[SerializedNamespace(NamespaceUri::UDT)]
-final class IndicatorStringType implements ValueObjectInterface
+final class IndicatorStringType
{
#[XmlValue(cdata: false)]
private string $value;
diff --git a/src/UnqualifiedDataType/IndicatorType.php b/src/UnqualifiedDataType/IndicatorType.php
index 3411a8c..d31acf9 100644
--- a/src/UnqualifiedDataType/IndicatorType.php
+++ b/src/UnqualifiedDataType/IndicatorType.php
@@ -6,12 +6,10 @@
use JMS\Serializer\Annotation\XmlElement;
use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
/**
* Unqualified indicator data type.
*/
-#[SerializedNamespace(NamespaceUri::UDT)]
final readonly class IndicatorType
{
/**
diff --git a/src/UnqualifiedDataType/MeasureType.php b/src/UnqualifiedDataType/MeasureType.php
index ec25629..0af7f20 100644
--- a/src/UnqualifiedDataType/MeasureType.php
+++ b/src/UnqualifiedDataType/MeasureType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Unqualified measure data type.
*/
-#[SerializedNamespace(NamespaceUri::UDT)]
-final readonly class MeasureType implements ValueObjectInterface
+final readonly class MeasureType
{
/**
* Measure value.
diff --git a/src/UnqualifiedDataType/NumericType.php b/src/UnqualifiedDataType/NumericType.php
index 87f48d8..87b7d8a 100644
--- a/src/UnqualifiedDataType/NumericType.php
+++ b/src/UnqualifiedDataType/NumericType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Unqualified numeric data type.
*/
-#[SerializedNamespace(NamespaceUri::UDT)]
-final readonly class NumericType implements ValueObjectInterface
+final readonly class NumericType
{
/**
* Numeric value.
diff --git a/src/UnqualifiedDataType/PercentType.php b/src/UnqualifiedDataType/PercentType.php
index 3d7462f..ca3a7f3 100644
--- a/src/UnqualifiedDataType/PercentType.php
+++ b/src/UnqualifiedDataType/PercentType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Unqualified percent data type.
*/
-#[SerializedNamespace(NamespaceUri::UDT)]
-final readonly class PercentType implements ValueObjectInterface
+final readonly class PercentType
{
/**
* Percent value.
diff --git a/src/UnqualifiedDataType/QuantityType.php b/src/UnqualifiedDataType/QuantityType.php
index bf168a1..a7d4707 100644
--- a/src/UnqualifiedDataType/QuantityType.php
+++ b/src/UnqualifiedDataType/QuantityType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Unqualified quantity data type.
*/
-#[SerializedNamespace(NamespaceUri::UDT)]
-final readonly class QuantityType implements ValueObjectInterface
+final readonly class QuantityType
{
/**
* Quantity value.
diff --git a/src/UnqualifiedDataType/TextType.php b/src/UnqualifiedDataType/TextType.php
index 553444d..fc03947 100644
--- a/src/UnqualifiedDataType/TextType.php
+++ b/src/UnqualifiedDataType/TextType.php
@@ -6,15 +6,11 @@
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Enum\NamespaceUri;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\Serializer\SerializedNamespace;
-use TiimePDP\CrossDomainAcknowledgementAndResponse\ValueObjectInterface;
/**
* Unqualified text data type.
*/
-#[SerializedNamespace(NamespaceUri::UDT)]
-final readonly class TextType implements ValueObjectInterface
+final readonly class TextType
{
/**
* Text value.
diff --git a/src/ValueObjectInterface.php b/src/ValueObjectInterface.php
deleted file mode 100644
index a4d78da..0000000
--- a/src/ValueObjectInterface.php
+++ /dev/null
@@ -1,10 +0,0 @@
-buildCdarMessage();
-
- // Act
- $xml = $serializer->serialize($cdar);
-
- // Assert
- $this->assertXmlStringEqualsXmlFile(__DIR__.'/../data/expected_serialize.xml', $xml);
- }
-
- public function testDeserialize(): void
- {
- // Arrange
- $serializer = new JmsSerializer();
- /** @var string $xml */
- $xml = file_get_contents(__DIR__.'/../data/UC1_F202500003_01-CDV-200_Deposee.xml');
-
- // Act
- $cdar = $serializer->deserialize($xml);
-
- // Assert
- $exchangedDocumentContext = $cdar->getExchangedDocumentContext();
- $this->assertNotNull($exchangedDocumentContext);
- $this->assertSame('REGULATED', $exchangedDocumentContext->getBusinessProcessSpecifiedDocumentContextParameter()?->getID()->getValue());
- $this->assertSame('urn.cpro.gouv.fr:1p0:CDV:invoice', $exchangedDocumentContext->getGuidelineSpecifiedDocumentContextParameter()->getID()->getValue());
-
- $this->assertSame('UC1_F202500003_01-CDV-200_Déposée', $cdar->getExchangedDocument()->getName()?->getValue());
- $this->assertCount(2, $cdar->getExchangedDocument()->getRecipientTradeParty());
- $recipientTradeParty1 = $cdar->getExchangedDocument()->getRecipientTradeParty()[0];
- $this->assertNotNull($recipientTradeParty1->getGlobalID());
- $this->assertCount(1, $recipientTradeParty1->getGlobalID());
- $globalId = $recipientTradeParty1->getGlobalID()[0];
- $this->assertSame('100000009', $globalId->getValue());
- $this->assertSame('VENDEUR', $recipientTradeParty1->getName()?->getValue());
-
- $recipientTradeParty2 = $cdar->getExchangedDocument()->getRecipientTradeParty()[1];
- $this->assertNotNull($recipientTradeParty2->getGlobalID());
- $this->assertCount(1, $recipientTradeParty2->getGlobalID());
- $globalId2 = $recipientTradeParty2->getGlobalID()[0];
- $this->assertSame('9998', $globalId2->getValue());
- $this->assertSame('PPF', $recipientTradeParty2->getName()?->getValue());
-
- $this->assertCount(1, $cdar->getAcknowledgementDocument());
- $acknowledgementDocument = $cdar->getAcknowledgementDocument()[0];
- $this->assertNotNull($acknowledgementDocument->getReferenceReferencedDocument());
- $this->assertCount(1, $acknowledgementDocument->getReferenceReferencedDocument());
- $referenceReferencedDocument = $acknowledgementDocument->getReferenceReferencedDocument()[0];
- $this->assertSame('F202500003', $referenceReferencedDocument->getIssuerAssignedID()?->getValue());
- $this->assertSame('200', $referenceReferencedDocument->getProcessConditionCode()?->getValue());
- $this->assertNotNull($referenceReferencedDocument->getProcessCondition());
- $this->assertCount(1, $referenceReferencedDocument->getProcessCondition());
- $this->assertSame('Déposée', $referenceReferencedDocument->getProcessCondition()[0]->getValue());
- }
-
- private function buildCdarMessage(): CrossDomainAcknowledgementAndResponse
- {
- // ExchangedDocumentContext
- $businessProcessParam = new DocumentContextParameterType(
- ID: new IDType('REGULATED')
- );
-
- $guidelineParam = new DocumentContextParameterType(
- ID: new IDType('urn.cpro.gouv.fr:1p0:CDV:invoice')
- );
-
- $exchangedDocumentContext = new ExchangedDocumentContextType(
- guidelineSpecifiedDocumentContextParameter: $guidelineParam,
- businessProcessSpecifiedDocumentContextParameter: $businessProcessParam
- );
-
- // Trade parties
- $senderParty = new TradePartyType(
- roleCode: new PartyRoleCodeType('WK')
- );
-
- $issuerParty = new TradePartyType(
- roleCode: new PartyRoleCodeType('WK')
- );
-
- $recipient1 = new TradePartyType(
- globalID: [new IDType('100000009', schemeID: '0002')],
- name: new TextType('VENDEUR'),
- roleCode: new PartyRoleCodeType('SE')
- );
-
- $recipient2 = new TradePartyType(
- globalID: [new IDType('9998', schemeID: '0238')],
- name: new TextType('PPF'),
- roleCode: new PartyRoleCodeType('DFH')
- );
-
- // ExchangedDocument
- $exchangedDocument = new ExchangedDocumentType(
- recipientTradeParty: [$recipient1, $recipient2],
- name: new TextType('UC1_F202500003_01-CDV-200_Déposée'),
- issueDateTime: new DateTimeType(
- dateTimeString: new DateTimeStringType('20250701151500', '204'),
- ),
- senderTradeParty: $senderParty,
- issuerTradeParty: $issuerParty
- );
-
- // Referenced document
- $refDocIssuerParty = new TradePartyType(
- globalID: [new IDType('100000009')]
- );
-
- $referencedDocument = new ReferencedDocumentType(
- issuerAssignedID: new IDType('F202500003'),
- typeCode: new DocumentCodeType(DocumentNameCode::CODE_380->value),
- receiptDateTime: new DateTimeType(
- dateTimeString: new DateTimeStringType('20250701151500', '204'),
- ),
- formattedIssueDateTime: new FormattedDateTimeType(
- dateTimeString: new \TiimePDP\CrossDomainAcknowledgementAndResponse\QualifiedDataType\DateTimeStringType('20250701', format: TimePointFormatCode::CCYYMMDD)
- ),
- processConditionCode: new CodeType('200'),
- processCondition: [new TextType('Déposée')],
- issuerTradeParty: $refDocIssuerParty
- );
-
- // AcknowledgementDocument
- $acknowledgementDocument = new AcknowledgementDocumentType(
- multipleReferencesIndicator: new IndicatorType(indicator: false),
- typeCode: new DocumentCodeType(DocumentNameCode::CODE_305->value),
- issueDateTime: new DateTimeType(
- dateTimeString: new DateTimeStringType('20250701151500', '204'),
- ),
- referenceReferencedDocument: [$referencedDocument],
- );
-
- // Complete CDAR message
- return new CrossDomainAcknowledgementAndResponse(
- exchangedDocument: $exchangedDocument,
- acknowledgementDocument: [$acknowledgementDocument],
- exchangedDocumentContext: $exchangedDocumentContext
- );
- }
-}
diff --git a/tests/Serializer/SerializerTest.php b/tests/Serializer/SerializerTest.php
index b491788..cdcdd34 100644
--- a/tests/Serializer/SerializerTest.php
+++ b/tests/Serializer/SerializerTest.php
@@ -29,235 +29,64 @@
#[CoversClass(Serializer::class)]
final class SerializerTest extends TestCase
{
- private Serializer $serializer;
-
- protected function setUp(): void
- {
- $this->serializer = new Serializer();
- }
-
- /**
- * Test basic serialization of a simple message.
- */
- public function testSerializeBasicMessage(): void
- {
- $document = new ExchangedDocumentType(
- recipientTradeParty: [],
- ID: new IDType('DOC-001'),
- name: new TextType('Test Document'),
- );
-
- $cdar = new CrossDomainAcknowledgementAndResponse(
- exchangedDocument: $document,
- acknowledgementDocument: [],
- );
-
- $xml = $this->serializer->serialize($cdar);
-
- $this->assertStringContainsString('', $xml);
- $this->assertStringContainsString('assertStringContainsString('', $xml);
- }
-
- /**
- * Test serialization includes namespaces.
- */
- public function testSerializeIncludesNamespaces(): void
- {
- $document = new ExchangedDocumentType(
- recipientTradeParty: [],
- );
-
- $cdar = new CrossDomainAcknowledgementAndResponse(
- exchangedDocument: $document,
- acknowledgementDocument: [],
- );
-
- $xml = $this->serializer->serialize($cdar);
-
- $this->assertStringContainsString('xmlns:rsm=', $xml);
- $this->assertStringContainsString('xmlns:ram=', $xml);
- $this->assertStringContainsString('xmlns:udt=', $xml);
- $this->assertStringContainsString('xmlns:qdt=', $xml);
- }
-
- /**
- * Test serialization with nested objects.
- */
- public function testSerializeNestedObjects(): void
- {
- $sender = new TradePartyType(
- ID: [],
- globalID: [],
- name: new TextType('Sender Company'),
- );
-
- $recipient = new TradePartyType(
- ID: [],
- globalID: [],
- name: new TextType('Recipient Company'),
- );
-
- $document = new ExchangedDocumentType(
- recipientTradeParty: [$recipient],
- ID: new IDType('DOC-001'),
- senderTradeParty: $sender,
- );
-
- $cdar = new CrossDomainAcknowledgementAndResponse(
- exchangedDocument: $document,
- acknowledgementDocument: [],
- );
-
- $xml = $this->serializer->serialize($cdar);
-
- $this->assertStringContainsString('', $xml);
- $this->assertStringContainsString('', $xml);
- $this->assertStringContainsString('Sender Company', $xml);
- $this->assertStringContainsString('Recipient Company', $xml);
- }
-
- /**
- * Test null values are omitted.
- */
- public function testSerializeOmitsNullValues(): void
- {
- $document = new ExchangedDocumentType(
- recipientTradeParty: [],
- ID: new IDType('DOC-001'),
- // name is null
- // senderTradeParty is null
- );
-
- $cdar = new CrossDomainAcknowledgementAndResponse(
- exchangedDocument: $document,
- acknowledgementDocument: [],
- // exchangedDocumentContext is null
- );
-
- $xml = $this->serializer->serialize($cdar);
-
- // Should contain the ID value
- $this->assertStringContainsString('DOC-001', $xml);
- // Should not contain elements for null properties
- $this->assertStringNotContainsString('assertStringNotContainsString('assertStringNotContainsString('buildCdarMessage();
- $cdar = new CrossDomainAcknowledgementAndResponse(
- exchangedDocument: $document,
- acknowledgementDocument: [],
- );
+ // Act
+ $xml = $serializer->serialize($cdar);
- $xml = $this->serializer->serialize($cdar);
-
- // Try to load the XML to verify it's well-formed
- $doc = new \DOMDocument();
- $result = @$doc->loadXML($xml);
-
- $this->assertTrue($result, 'Generated XML is not well-formed');
+ // Assert
+ $this->assertXmlStringEqualsXmlFile(__DIR__.'/../data/expected_serialize.xml', $xml);
}
- /**
- * Test serialization with multiple items in array.
- */
- public function testSerializeArrayOfObjects(): void
+ public function testDeserialize(): void
{
- $recipient1 = new TradePartyType(
- ID: [],
- globalID: [],
- name: new TextType('Recipient 1'),
- );
-
- $recipient2 = new TradePartyType(
- ID: [],
- globalID: [],
- name: new TextType('Recipient 2'),
- );
-
- $document = new ExchangedDocumentType(
- recipientTradeParty: [$recipient1, $recipient2],
- );
-
- $cdar = new CrossDomainAcknowledgementAndResponse(
- exchangedDocument: $document,
- acknowledgementDocument: [],
- );
-
- $xml = $this->serializer->serialize($cdar);
-
- // Count occurrences of RecipientTradeParty (opening tags only)
- $count = \substr_count($xml, 'assertEquals(2, $count, 'Should have 2 RecipientTradeParty elements');
-
- // Verify both recipients are present
- $this->assertStringContainsString('Recipient 1', $xml);
- $this->assertStringContainsString('Recipient 2', $xml);
- }
-
- /**
- * Test complete CDAR message serialization with real data
- * Based on UC1_F202500003_01-CDV-200_Deposee.xml.
- */
- public function testSerializeCompleteRealMessage(): void
- {
- $cdar = $this->buildRealCdarMessage();
- $xml = $this->serializer->serialize($cdar, true);
-
- // Assert XML well-formed
- $doc = new \DOMDocument();
- $result = $doc->loadXML($xml);
- $this->assertTrue($result, 'Generated XML should be well-formed');
-
- // Assert basic structure
- $this->assertStringContainsString('', $xml);
- $this->assertStringContainsString('assertStringContainsString('assertStringContainsString('assertStringContainsString('assertStringContainsString('assertStringContainsString('assertStringContainsString('assertStringContainsString('assertStringContainsString('assertStringContainsString('xmlns:rsm=', $xml);
- $this->assertStringContainsString('xmlns:ram=', $xml);
- $this->assertStringContainsString('xmlns:udt=', $xml);
- $this->assertStringContainsString('xmlns:qdt=', $xml);
-
- // Assert key data present
- $this->assertStringContainsString('REGULATED', $xml);
- $this->assertStringContainsString('urn.cpro.gouv.fr:1p0:CDV:invoice', $xml);
- $this->assertStringContainsString('UC1_F202500003_01-CDV-200_Déposée', $xml);
- $this->assertStringContainsString('100000009', $xml);
- $this->assertStringContainsString('VENDEUR', $xml);
- $this->assertStringContainsString('F202500003', $xml);
- $this->assertStringContainsString('Déposée', $xml);
+ // Arrange
+ $serializer = new Serializer();
+ /** @var string $xml */
+ $xml = file_get_contents(__DIR__.'/../data/UC1_F202500003_01-CDV-200_Deposee.xml');
+
+ // Act
+ $cdar = $serializer->deserialize($xml);
+
+ // Assert
+ $exchangedDocumentContext = $cdar->getExchangedDocumentContext();
+ $this->assertNotNull($exchangedDocumentContext);
+ $this->assertSame('REGULATED', $exchangedDocumentContext->getBusinessProcessSpecifiedDocumentContextParameter()?->getID()->getValue());
+ $this->assertSame('urn.cpro.gouv.fr:1p0:CDV:invoice', $exchangedDocumentContext->getGuidelineSpecifiedDocumentContextParameter()->getID()->getValue());
+
+ $this->assertSame('UC1_F202500003_01-CDV-200_Déposée', $cdar->getExchangedDocument()->getName()?->getValue());
+ $this->assertCount(2, $cdar->getExchangedDocument()->getRecipientTradeParty());
+ $recipientTradeParty1 = $cdar->getExchangedDocument()->getRecipientTradeParty()[0];
+ $this->assertNotNull($recipientTradeParty1->getGlobalID());
+ $this->assertCount(1, $recipientTradeParty1->getGlobalID());
+ $globalId = $recipientTradeParty1->getGlobalID()[0];
+ $this->assertSame('100000009', $globalId->getValue());
+ $this->assertSame('VENDEUR', $recipientTradeParty1->getName()?->getValue());
+
+ $recipientTradeParty2 = $cdar->getExchangedDocument()->getRecipientTradeParty()[1];
+ $this->assertNotNull($recipientTradeParty2->getGlobalID());
+ $this->assertCount(1, $recipientTradeParty2->getGlobalID());
+ $globalId2 = $recipientTradeParty2->getGlobalID()[0];
+ $this->assertSame('9998', $globalId2->getValue());
+ $this->assertSame('PPF', $recipientTradeParty2->getName()?->getValue());
+
+ $this->assertCount(1, $cdar->getAcknowledgementDocument());
+ $acknowledgementDocument = $cdar->getAcknowledgementDocument()[0];
+ $this->assertNotNull($acknowledgementDocument->getReferenceReferencedDocument());
+ $this->assertCount(1, $acknowledgementDocument->getReferenceReferencedDocument());
+ $referenceReferencedDocument = $acknowledgementDocument->getReferenceReferencedDocument()[0];
+ $this->assertSame('F202500003', $referenceReferencedDocument->getIssuerAssignedID()?->getValue());
+ $this->assertSame('200', $referenceReferencedDocument->getProcessConditionCode()?->getValue());
+ $this->assertNotNull($referenceReferencedDocument->getProcessCondition());
+ $this->assertCount(1, $referenceReferencedDocument->getProcessCondition());
+ $this->assertSame('Déposée', $referenceReferencedDocument->getProcessCondition()[0]->getValue());
}
- /**
- * Build a complete CDAR message with real data
- * Based on UC1_F202500003_01-CDV-200_Deposee.xml.
- */
- private function buildRealCdarMessage(): CrossDomainAcknowledgementAndResponse
+ private function buildCdarMessage(): CrossDomainAcknowledgementAndResponse
{
// ExchangedDocumentContext
$businessProcessParam = new DocumentContextParameterType(
@@ -275,26 +104,20 @@ private function buildRealCdarMessage(): CrossDomainAcknowledgementAndResponse
// Trade parties
$senderParty = new TradePartyType(
- ID: [],
- globalID: [],
roleCode: new PartyRoleCodeType('WK')
);
$issuerParty = new TradePartyType(
- ID: [],
- globalID: [],
roleCode: new PartyRoleCodeType('WK')
);
$recipient1 = new TradePartyType(
- ID: [],
globalID: [new IDType('100000009', schemeID: '0002')],
name: new TextType('VENDEUR'),
roleCode: new PartyRoleCodeType('SE')
);
$recipient2 = new TradePartyType(
- ID: [],
globalID: [new IDType('9998', schemeID: '0238')],
name: new TextType('PPF'),
roleCode: new PartyRoleCodeType('DFH')
@@ -313,7 +136,6 @@ private function buildRealCdarMessage(): CrossDomainAcknowledgementAndResponse
// Referenced document
$refDocIssuerParty = new TradePartyType(
- ID: [],
globalID: [new IDType('100000009')]
);