@@ -687,6 +687,26 @@ protected function setAttributeValue(object $object, string $attribute, $value,
687
687
688
688
$ this ->assertSame ('scalar ' , $ normalizer ->denormalize ('scalar ' , XmlScalarDummy::class, 'xml ' )->value );
689
689
}
690
+
691
+ /**
692
+ * @dataProvider provideBooleanTypesData
693
+ */
694
+ public function testDenormalizeBooleanTypesWithNotMatchingData (array $ data , string $ type )
695
+ {
696
+ $ normalizer = new AbstractObjectNormalizerWithMetadataAndPropertyTypeExtractors ();
697
+
698
+ $ this ->expectException (NotNormalizableValueException::class);
699
+
700
+ $ normalizer ->denormalize ($ data , $ type );
701
+ }
702
+
703
+ public function provideBooleanTypesData ()
704
+ {
705
+ return [
706
+ [['foo ' => true ], FalsePropertyDummy::class],
707
+ [['foo ' => false ], TruePropertyDummy::class],
708
+ ];
709
+ }
690
710
}
691
711
692
712
class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
@@ -816,6 +836,18 @@ class XmlScalarDummy
816
836
public $ value ;
817
837
}
818
838
839
+ class FalsePropertyDummy
840
+ {
841
+ /** @var false */
842
+ public $ foo ;
843
+ }
844
+
845
+ class TruePropertyDummy
846
+ {
847
+ /** @var true */
848
+ public $ foo ;
849
+ }
850
+
819
851
class SerializerCollectionDummy implements SerializerInterface, DenormalizerInterface
820
852
{
821
853
private $ normalizers ;
@@ -936,3 +968,28 @@ public function __sleep(): array
936
968
throw new \Error ('not serializable ' );
937
969
}
938
970
}
971
+
972
+ class AbstractObjectNormalizerWithMetadataAndPropertyTypeExtractors extends AbstractObjectNormalizer
973
+ {
974
+ public function __construct ()
975
+ {
976
+ parent ::__construct (new ClassMetadataFactory (new AnnotationLoader ()), null , new PropertyInfoExtractor ([], [new PhpDocExtractor (), new ReflectionExtractor ()]));
977
+ }
978
+
979
+ protected function extractAttributes (object $ object , ?string $ format = null , array $ context = []): array
980
+ {
981
+ return [];
982
+ }
983
+
984
+ protected function getAttributeValue (object $ object , string $ attribute , ?string $ format = null , array $ context = [])
985
+ {
986
+ return null ;
987
+ }
988
+
989
+ protected function setAttributeValue (object $ object , string $ attribute , $ value , ?string $ format = null , array $ context = []): void
990
+ {
991
+ if (property_exists ($ object , $ attribute )) {
992
+ $ object ->$ attribute = $ value ;
993
+ }
994
+ }
995
+ }
0 commit comments