@@ -71,6 +71,27 @@ public function testInvalidFlags()
7171 ->assertRaised ();
7272 }
7373
74+ /**
75+ * @dataProvider getDeprecationOnLinesData
76+ */
77+ public function testDeprecationTriggersParseException (int $ yamlLine , string $ yamlValue )
78+ {
79+ $ lines = explode ("\n" , $ yamlValue );
80+ $ errorLine = end ($ lines );
81+ $ expectedError = 'This is a simulated deprecation at line ' .$ yamlLine .' (near " ' .$ errorLine .'") ' ;
82+
83+ $ constraint = new Yaml (
84+ message: 'myMessageTest ' ,
85+ flags: YamlParser::PARSE_OBJECT ,
86+ );
87+ $ this ->validator ->validate ($ yamlValue , $ constraint );
88+ $ this ->buildViolation ('myMessageTest ' )
89+ ->setParameter ('{{ error }} ' , $ expectedError )
90+ ->setParameter ('{{ line }} ' , $ yamlLine )
91+ ->setCode (Yaml::INVALID_YAML_ERROR )
92+ ->assertRaised ();
93+ }
94+
7495 public static function getValidValues ()
7596 {
7697 return [
@@ -94,4 +115,34 @@ public static function getInvalidValues(): array
94115 ["key: \nvalue " , 'Unable to parse at line 2 (near "value"). ' , 2 ],
95116 ];
96117 }
118+
119+ /**
120+ * @return array<string, array{0: int, 1: string}>
121+ */
122+ public static function getDeprecationOnLinesData (): array
123+ {
124+ $ serialized = serialize (new DeprecatedObjectFixture ());
125+
126+ return [
127+ 'deprecation at line 1 ' => [1 , "object: !php/object ' " .$ serialized ."' " ],
128+ 'deprecation at line 2 ' => [2 , "valid: yaml \nobject: !php/object ' " .$ serialized ."' " ],
129+ 'deprecation at line 5 ' => [5 , "line1: value \nline2: value \nline3: value \nline4: value \nobject: !php/object ' " .$ serialized ."' " ],
130+ ];
131+ }
132+ }
133+
134+ /**
135+ * Fixture class for triggering deprecation during unserialize.
136+ */
137+ class DeprecatedObjectFixture
138+ {
139+ public function __serialize (): array
140+ {
141+ return [];
142+ }
143+
144+ public function __unserialize (array $ data ): void
145+ {
146+ @trigger_error ('This is a simulated deprecation ' , \E_USER_DEPRECATED );
147+ }
97148}
0 commit comments