|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Tests for the \PHP_CodeSniffer\Util\Common::getSniffCode() method. |
| 4 | + * |
| 5 | + * @author Juliette Reinders Folmer <[email protected]> |
| 6 | + * @copyright 2024 PHPCSStandards and contributors |
| 7 | + * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence |
| 8 | + */ |
| 9 | + |
| 10 | +namespace PHP_CodeSniffer\Tests\Core\Util\Common; |
| 11 | + |
| 12 | +use PHP_CodeSniffer\Util\Common; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | + |
| 15 | +/** |
| 16 | + * Tests for the \PHP_CodeSniffer\Util\Common::getSniffCode() method. |
| 17 | + * |
| 18 | + * @covers \PHP_CodeSniffer\Util\Common::getSniffCode |
| 19 | + */ |
| 20 | +final class GetSniffCodeTest extends TestCase |
| 21 | +{ |
| 22 | + |
| 23 | + |
| 24 | + /** |
| 25 | + * Test transforming a sniff class name to a sniff code. |
| 26 | + * |
| 27 | + * @param string $fqnClass A fully qualified sniff class name. |
| 28 | + * @param string $expected Expected function output. |
| 29 | + * |
| 30 | + * @dataProvider dataGetSniffCode |
| 31 | + * |
| 32 | + * @return void |
| 33 | + */ |
| 34 | + public function testGetSniffCode($fqnClass, $expected) |
| 35 | + { |
| 36 | + $this->assertSame($expected, Common::getSniffCode($fqnClass)); |
| 37 | + |
| 38 | + }//end testGetSniffCode() |
| 39 | + |
| 40 | + |
| 41 | + /** |
| 42 | + * Data provider. |
| 43 | + * |
| 44 | + * @see testGetSniffCode() |
| 45 | + * |
| 46 | + * @return array<string, array<string, string>> |
| 47 | + */ |
| 48 | + public static function dataGetSniffCode() |
| 49 | + { |
| 50 | + return [ |
| 51 | + 'PHPCS native sniff' => [ |
| 52 | + 'fqnClass' => 'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\Arrays\\ArrayIndentSniff', |
| 53 | + 'expected' => 'Generic.Arrays.ArrayIndent', |
| 54 | + ], |
| 55 | + 'Class is a PHPCS native test class' => [ |
| 56 | + 'fqnClass' => 'PHP_CodeSniffer\\Standards\\Generic\\Tests\\Arrays\\ArrayIndentUnitTest', |
| 57 | + 'expected' => 'Generic.Arrays.ArrayIndent', |
| 58 | + ], |
| 59 | + 'Sniff in external standard without namespace prefix' => [ |
| 60 | + 'fqnClass' => 'MyStandard\\Sniffs\\PHP\\MyNameSniff', |
| 61 | + 'expected' => 'MyStandard.PHP.MyName', |
| 62 | + ], |
| 63 | + 'Test in external standard without namespace prefix' => [ |
| 64 | + 'fqnClass' => 'MyStandard\\Tests\\PHP\\MyNameSniff', |
| 65 | + 'expected' => 'MyStandard.PHP.MyName', |
| 66 | + ], |
| 67 | + 'Sniff in external standard with namespace prefix' => [ |
| 68 | + 'fqnClass' => 'Vendor\\Package\\MyStandard\\Sniffs\\Category\\AnalyzeMeSniff', |
| 69 | + 'expected' => 'MyStandard.Category.AnalyzeMe', |
| 70 | + ], |
| 71 | + 'Test in external standard with namespace prefix' => [ |
| 72 | + 'fqnClass' => 'Vendor\\Package\\MyStandard\\Tests\\Category\\AnalyzeMeUnitTest', |
| 73 | + 'expected' => 'MyStandard.Category.AnalyzeMe', |
| 74 | + ], |
| 75 | + ]; |
| 76 | + |
| 77 | + }//end dataGetSniffCode() |
| 78 | + |
| 79 | + |
| 80 | +}//end class |
0 commit comments