Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Encoder/ObjectEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static function (string $normalizePropertyName, Property $property) use ($object
$iso = $objectAccess->isos[$normalizePropertyName];

return match(true) {
$isAttribute => $value ? (new AttributeBuilder(
$isAttribute => $value !== null ? (new AttributeBuilder(
$type,
$iso->to($value)
))(...) : $defaultAction,
Expand Down
17 changes: 17 additions & 0 deletions tests/Unit/Encoder/ObjectEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ public static function provideIsomorphicCases(): iterable
'xml' => '<user active="true"><hat><color>green</color></hat></user>',
'data' => new User(active: true, hat: new Hat('green')),
];
yield 'with-falsy-attribute' => [
...$baseConfig,
'context' => self::createContext($xsdType, self::buildTypes(activeAsAttribute: true)),
'xml' => '<user active="false"><hat><color>green</color></hat></user>',
'data' => (object)[
'active' => false,
'hat' => (object)[
'color' => 'green',
],
],
];
yield 'class-objects-with-falsy-attribute' => [
'encoder' => new ObjectEncoder(User::class),
'context' => $withClassMap(self::createContext($xsdType, self::buildTypes(activeAsAttribute: true))),
'xml' => '<user active="false"><hat><color>green</color></hat></user>',
'data' => new User(active: false, hat: new Hat('green')),
];

yield 'wsdl-example-objects' => [
...$baseConfig,
Expand Down