@@ -764,20 +764,26 @@ public function testUnionTypeDeserializableWithoutAllowedExtraAttributes()
764
764
['json ' => new JsonEncoder ()]
765
765
);
766
766
767
- $ actual = $ serializer ->deserialize ('{ "v": { "a": 0 }} ' , DummyUnionWithAAndB ::class, 'json ' , [
767
+ $ actual = $ serializer ->deserialize ('{ "v": { "a": 0 }} ' , DummyUnionWithAAndCAndB ::class, 'json ' , [
768
768
AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => false ,
769
769
]);
770
770
771
- $ this ->assertEquals (new DummyUnionWithAAndB (new DummyATypeForUnion ()), $ actual );
771
+ $ this ->assertEquals (new DummyUnionWithAAndCAndB (new DummyATypeForUnion ()), $ actual );
772
772
773
- $ actual = $ serializer ->deserialize ('{ "v": { "b": 1 }} ' , DummyUnionWithAAndB ::class, 'json ' , [
773
+ $ actual = $ serializer ->deserialize ('{ "v": { "b": 1 }} ' , DummyUnionWithAAndCAndB ::class, 'json ' , [
774
774
AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => false ,
775
775
]);
776
776
777
- $ this ->assertEquals (new DummyUnionWithAAndB (new DummyBTypeForUnion ()), $ actual );
777
+ $ this ->assertEquals (new DummyUnionWithAAndCAndB (new DummyBTypeForUnion ()), $ actual );
778
+
779
+ $ actual = $ serializer ->deserialize ('{ "v": { "c": 3 }} ' , DummyUnionWithAAndCAndB::class, 'json ' , [
780
+ AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => false ,
781
+ ]);
782
+
783
+ $ this ->assertEquals (new DummyUnionWithAAndCAndB (new DummyCTypeForUnion (3 )), $ actual );
778
784
779
785
$ this ->expectException (ExtraAttributesException::class);
780
- $ serializer ->deserialize ('{ "v": { "b": 1, "c ": "i am not allowed" }} ' , DummyUnionWithAAndB ::class, 'json ' , [
786
+ $ serializer ->deserialize ('{ "v": { "b": 1, "d ": "i am not allowed" }} ' , DummyUnionWithAAndCAndB ::class, 'json ' , [
781
787
AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => false ,
782
788
]);
783
789
}
@@ -1262,13 +1268,23 @@ class DummyBTypeForUnion
1262
1268
public $ b = 1 ;
1263
1269
}
1264
1270
1265
- class DummyUnionWithAAndB
1271
+ class DummyCTypeForUnion
1272
+ {
1273
+ public $ c = 2 ;
1274
+
1275
+ public function __construct ($ c )
1276
+ {
1277
+ $ this ->c = $ c ;
1278
+ }
1279
+ }
1280
+
1281
+ class DummyUnionWithAAndCAndB
1266
1282
{
1267
- /** @var DummyATypeForUnion|DummyBTypeForUnion */
1283
+ /** @var DummyATypeForUnion|DummyCTypeForUnion| DummyBTypeForUnion */
1268
1284
public $ v ;
1269
1285
1270
1286
/**
1271
- * @param DummyATypeForUnion|DummyBTypeForUnion $v
1287
+ * @param DummyATypeForUnion|DummyCTypeForUnion| DummyBTypeForUnion $v
1272
1288
*/
1273
1289
public function __construct ($ v )
1274
1290
{
0 commit comments