55namespace SbWereWolf \XmlNavigator \Test \Unit \Conversion ;
66
77use InvalidArgumentException ;
8- use PHPUnit \Framework \Attributes \DataProvider ;
98use PHPUnit \Framework \TestCase ;
109use ReflectionMethod ;
1110use SbWereWolf \XmlNavigator \Conversion \FastXmlToArray ;
@@ -113,7 +112,9 @@ public function testPrettyPrintSupportsXmlTextAndXmlFile(): void
113112 self ::assertSame ($ expected , FastXmlToArray::prettyPrint ('' , $ xmlFile ));
114113 }
115114
116- #[DataProvider('missingSourceProvider ' )]
115+ /**
116+ * @dataProvider missingSourceProvider
117+ */
117118 public function testMethodsRejectMissingXmlSource (string $ method ): void
118119 {
119120 $ this ->expectException (InvalidArgumentException::class);
@@ -137,7 +138,9 @@ public static function missingSourceProvider(): array
137138 ];
138139 }
139140
140- #[DataProvider('ambiguousSourceProvider ' )]
141+ /**
142+ * @dataProvider ambiguousSourceProvider
143+ */
141144 public function testMethodsRejectAmbiguousXmlSource (
142145 string $ method ,
143146 string $ xmlText ,
@@ -208,7 +211,9 @@ public function testPrettyPrintRejectsMalformedXmlText(): void
208211 FastXmlToArray::prettyPrint ('<broken> ' );
209212 }
210213
211- #[DataProvider('malformedUriProvider ' )]
214+ /**
215+ * @dataProvider malformedUriProvider
216+ */
212217 public function testMethodsRejectMalformedXmlFile (string $ method ): void
213218 {
214219 $ this ->expectException (InvalidArgumentException::class);
@@ -266,28 +271,39 @@ public function testParseRootElementRejectsBufferedLibxmlErrorsAfterParse(): voi
266271 );
267272 /** @noinspection PhpExpressionResultUnusedInspection */
268273 $ method ->setAccessible (true );
269-
270- $ this ->expectException (InvalidArgumentException::class);
271- $ this ->expectExceptionCode (-669 );
272- $ this ->expectExceptionMessage (
273- 'Unable to parse XML from $xmlText. ' .
274- 'Premature end of data in tag broken line 1 '
275- );
276-
277- $ method ->invoke (
278- null ,
279- '<root/> ' ,
280- '' ,
281- null ,
282- LIBXML_BIGLINES | LIBXML_COMPACT ,
283- static function (\XMLReader $ reader ): array {
284- $ dom = new \DOMDocument ();
285- @$ dom ->loadXML ('<broken> ' );
286-
287- return [
288- 'n ' => $ reader ->name ,
289- ];
290- }
291- );
274+ try {
275+ $ method ->invoke (
276+ null ,
277+ '<root/> ' ,
278+ '' ,
279+ null ,
280+ LIBXML_BIGLINES | LIBXML_COMPACT ,
281+ static function (\XMLReader $ reader ): array {
282+ $ dom = new \DOMDocument ();
283+ @$ dom ->loadXML ('<broken> ' );
284+
285+ return [
286+ 'n ' => $ reader ->name ,
287+ ];
288+ }
289+ );
290+ self ::fail ('Expected parsing exception was not thrown. ' );
291+ } catch (InvalidArgumentException $ exception ) {
292+ self ::assertSame (-669 , $ exception ->getCode ());
293+ self ::assertStringContainsString (
294+ 'Unable to parse XML from $xmlText. ' ,
295+ $ exception ->getMessage ()
296+ );
297+ self ::assertTrue (
298+ strpos (
299+ $ exception ->getMessage (),
300+ 'Premature end of data in tag broken line 1 '
301+ ) !== false
302+ || strpos (
303+ $ exception ->getMessage (),
304+ "EndTag: '</' not found "
305+ ) !== false
306+ );
307+ }
292308 }
293309}
0 commit comments