-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With nullable typed readonly properties (from PHP 8.1+) we face situ…
…ations where properties are not set after deserialization (Typed property...must not be accessed before initialization). This subscriber helps to handle these cases by adding properties to the payload so that they end up being null.
- Loading branch information
Showing
5 changed files
with
61 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -410,4 +410,54 @@ public function testDeserializeOneRowXml(): void | |
|
||
$this->assertXmlStringEqualsXmlString($xml, $resultingXml); | ||
} | ||
|
||
public function testDeserializeNullProperty(): void | ||
{ | ||
$xml = | ||
'<?xml version="1.0" encoding="UTF-8"?> | ||
<cXML payloadID="payload-id" timestamp="2000-01-01T00:00:00+00:00"> | ||
<Header> | ||
<From> | ||
<Credential domain="AribaNetworkUserId"> | ||
<Identity>[email protected]</Identity> | ||
</Credential> | ||
</From> | ||
<To> | ||
<Credential domain="DUNS"> | ||
<Identity>012345678</Identity> | ||
</Credential> | ||
</To> | ||
<Sender> | ||
<Credential domain="AribaNetworkUserId"> | ||
<Identity>[email protected]</Identity> | ||
<SharedSecret>abracadabra</SharedSecret> | ||
</Credential> | ||
<UserAgent>Network Hub 1.1</UserAgent> | ||
</Sender> | ||
</Header> | ||
<Request> | ||
<OrderRequest> | ||
<OrderRequestHeader orderDate="2000-01-01" orderID="order-id" type="new"> | ||
<Total> | ||
<Money currency="EUR">0.00</Money> | ||
</Total> | ||
<BillTo> | ||
<Address> | ||
<Name xml:lang="en">name</Name> | ||
</Address> | ||
</BillTo> | ||
</OrderRequestHeader> | ||
</OrderRequest> | ||
</Request> | ||
</cXML>'; | ||
|
||
$cxml = Serializer::create()->deserialize($xml); | ||
|
||
/** @var OrderRequest $orderRequest */ | ||
$orderRequest = $cxml->getRequest()->getPayload(); | ||
|
||
// Error: Typed property CXml\Model\Request\OrderRequestHeader::$shipTo must not be accessed before initialization | ||
$shipTo = $orderRequest->getOrderRequestHeader()->getShipTo(); | ||
$this->assertNull($shipTo); | ||
} | ||
} |