@@ -363,4 +363,64 @@ public function testFooterDoesntThrowWarningOnMissingTimezone()
363
363
}//end testFooterDoesntThrowWarningOnMissingTimezone()
364
364
365
365
366
+ /**
367
+ * Perfunctory test to verify that extenders which call deprecated methods will see a deprecation notice.
368
+ *
369
+ * Note: not all deprecated methods are tested as some need arguments.
370
+ *
371
+ * @param string $methodName Name of the deprecated method to test.
372
+ *
373
+ * @dataProvider dataCallingDeprecatedMethodThrowsDeprecationNotice
374
+ *
375
+ * @return void
376
+ */
377
+ public function testCallingDeprecatedMethodThrowsDeprecationNotice ($ methodName )
378
+ {
379
+ $ exceptionClass = 'PHPUnit\Framework\Error\Deprecated ' ;
380
+ if (class_exists ($ exceptionClass ) === false ) {
381
+ $ exceptionClass = 'PHPUnit_Framework_Error_Deprecated ' ;
382
+ }
383
+
384
+ $ regex = '`^The PHP_CodeSniffer \\\\Generators \\\\HTML::%s\(\) method is deprecated\. Use "echo [^\s]+::%s\(\)" instead\.$` ' ;
385
+ $ regex = sprintf ($ regex , preg_quote ($ methodName , '` ' ), str_replace ('print ' , 'getFormatted ' , $ methodName ));
386
+
387
+ if (method_exists ($ this , 'expectExceptionMessageMatches ' ) === true ) {
388
+ $ this ->expectException ($ exceptionClass );
389
+ $ this ->expectExceptionMessageMatches ($ regex );
390
+ } else if (method_exists ($ this , 'expectExceptionMessageRegExp ' ) === true ) {
391
+ // PHPUnit < 8.4.0.
392
+ $ this ->expectException ($ exceptionClass );
393
+ $ this ->expectExceptionMessageRegExp ($ regex );
394
+ } else {
395
+ // PHPUnit < 5.2.0.
396
+ $ this ->setExpectedExceptionRegExp ($ exceptionClass , $ regex );
397
+ }
398
+
399
+ // Set up the ruleset.
400
+ $ standard = __DIR__ .'/OneDocTest.xml ' ;
401
+ $ config = new ConfigDouble (["--standard= $ standard " ]);
402
+ $ ruleset = new Ruleset ($ config );
403
+
404
+ $ generator = new HTMLDouble ($ ruleset );
405
+ $ generator ->$ methodName ();
406
+
407
+ }//end testCallingDeprecatedMethodThrowsDeprecationNotice()
408
+
409
+
410
+ /**
411
+ * Data provider.
412
+ *
413
+ * @return array<string, array<string, string>>
414
+ */
415
+ public static function dataCallingDeprecatedMethodThrowsDeprecationNotice ()
416
+ {
417
+ return [
418
+ 'printHeader() ' => ['printHeader ' ],
419
+ 'printToc() ' => ['printToc ' ],
420
+ 'printFooter() ' => ['printFooter ' ],
421
+ ];
422
+
423
+ }//end dataCallingDeprecatedMethodThrowsDeprecationNotice()
424
+
425
+
366
426
}//end class
0 commit comments