|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +namespace CakeDC\PHPStan\Test\TestCase\Rule\Debug; |
| 5 | + |
| 6 | +use CakeDC\PHPStan\Rule\Debug\DisallowDebugFuncCallRule; |
| 7 | +use PHPStan\Rules\Rule; |
| 8 | +use PHPStan\Testing\RuleTestCase; |
| 9 | + |
| 10 | +class DisallowDebugFuncCallRuleTest extends RuleTestCase |
| 11 | +{ |
| 12 | + /** |
| 13 | + * @return \PHPStan\Rules\Rule |
| 14 | + */ |
| 15 | + protected function getRule(): Rule |
| 16 | + { |
| 17 | + // getRule() method needs to return an instance of the tested rule |
| 18 | + return new DisallowDebugFuncCallRule(); |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * @return void |
| 23 | + */ |
| 24 | + public function testRule(): void |
| 25 | + { |
| 26 | + // first argument: path to the example file that contains some errors that should be reported by MyRule |
| 27 | + // second argument: an array of expected errors, |
| 28 | + // each error consists of the asserted error message, and the asserted error file line |
| 29 | + $this->analyse([__DIR__ . '/Fake/FailingDebugUseLogic.php'], [ |
| 30 | + [ |
| 31 | + 'Use of debug function "debug" is not allowed. The use in shipped code is discouraged because they can leak sensitive information or clutter output.', |
| 32 | + 14, // asserted error line |
| 33 | + ], |
| 34 | + [ |
| 35 | + 'Use of debug function "debug_print_backtrace" is not allowed. The use in shipped code is discouraged because they can leak sensitive information or clutter output.', |
| 36 | + 15, // asserted error line |
| 37 | + ], |
| 38 | + [ |
| 39 | + 'Use of debug function "debug_zval_dump" is not allowed. The use in shipped code is discouraged because they can leak sensitive information or clutter output.', |
| 40 | + 16, // asserted error line |
| 41 | + ], |
| 42 | + [ |
| 43 | + 'Use of debug function "print_r" is not allowed. The use in shipped code is discouraged because they can leak sensitive information or clutter output.', |
| 44 | + 19, // asserted error line |
| 45 | + ], |
| 46 | + [ |
| 47 | + 'Use of debug function "print_r" is not allowed. The use in shipped code is discouraged because they can leak sensitive information or clutter output.', |
| 48 | + 20, // asserted error line |
| 49 | + ], |
| 50 | + [ |
| 51 | + 'Use of debug function "var_dump" is not allowed. The use in shipped code is discouraged because they can leak sensitive information or clutter output.', |
| 52 | + 21, // asserted error line |
| 53 | + ], |
| 54 | + [ |
| 55 | + 'Use of debug function "var_export" is not allowed. The use in shipped code is discouraged because they can leak sensitive information or clutter output.', |
| 56 | + 23, // asserted error line |
| 57 | + ], |
| 58 | + [ |
| 59 | + 'Use of debug function "var_export" is not allowed. The use in shipped code is discouraged because they can leak sensitive information or clutter output.', |
| 60 | + 24, // asserted error line |
| 61 | + ], |
| 62 | + [ |
| 63 | + 'Use of debug function "stackTrace" is not allowed. The use in shipped code is discouraged because they can leak sensitive information or clutter output.', |
| 64 | + 25, // asserted error line |
| 65 | + ], |
| 66 | + [ |
| 67 | + 'Use of debug function "pr" is not allowed. The use in shipped code is discouraged because they can leak sensitive information or clutter output.', |
| 68 | + 26, // asserted error line |
| 69 | + ], |
| 70 | + [ |
| 71 | + 'Use of debug function "dd" is not allowed. The use in shipped code is discouraged because they can leak sensitive information or clutter output.', |
| 72 | + 28, // asserted error line |
| 73 | + ], |
| 74 | + ]); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * @inheritDoc |
| 79 | + */ |
| 80 | + public static function getAdditionalConfigFiles(): array |
| 81 | + { |
| 82 | + return [__DIR__ . '/../../../../extension.neon']; |
| 83 | + } |
| 84 | +} |
0 commit comments