Skip to content

Commit

Permalink
Common::getSniffCode(): add tests
Browse files Browse the repository at this point in the history
Add initial set of tests for the `Common::getSniffCode()` method.

Related to 146
Related to [review comment in PR 446](#446 (comment)).
  • Loading branch information
jrfnl committed Jun 5, 2024
1 parent df258d4 commit c75c7d2
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions tests/Core/Util/Common/GetSniffCodeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Tests for the \PHP_CodeSniffer\Util\Common::getSniffCode() method.
*
* @author Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl>
* @copyright 2024 PHPCSStandards and contributors
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/

namespace PHP_CodeSniffer\Tests\Core\Util\Common;

use PHP_CodeSniffer\Util\Common;
use PHPUnit\Framework\TestCase;

/**
* Tests for the \PHP_CodeSniffer\Util\Common::getSniffCode() method.
*
* @covers \PHP_CodeSniffer\Util\Common::getSniffCode
*/
final class GetSniffCodeTest extends TestCase
{


/**
* Test transforming a sniff class name to a sniff code.
*
* @param string $fqnClass A fully qualified sniff class name.
* @param string $expected Expected function output.
*
* @dataProvider dataGetSniffCode
*
* @return void
*/
public function testGetSniffCode($fqnClass, $expected)
{
$this->assertSame($expected, Common::getSniffCode($fqnClass));

}//end testGetSniffCode()


/**
* Data provider.
*
* @see testGetSniffCode()
*
* @return array<string, array<string, string>>
*/
public static function dataGetSniffCode()
{
return [
'PHPCS native sniff' => [
'fqnClass' => 'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\Arrays\\ArrayIndentSniff',
'expected' => 'Generic.Arrays.ArrayIndent',
],
'Class is a PHPCS native test class' => [
'fqnClass' => 'PHP_CodeSniffer\\Standards\\Generic\\Tests\\Arrays\\ArrayIndentUnitTest',
'expected' => 'Generic.Arrays.ArrayIndent',
],
'Sniff in external standard without namespace prefix' => [
'fqnClass' => 'MyStandard\\Sniffs\\PHP\\MyNameSniff',
'expected' => 'MyStandard.PHP.MyName',
],
'Test in external standard without namespace prefix' => [
'fqnClass' => 'MyStandard\\Tests\\PHP\\MyNameSniff',
'expected' => 'MyStandard.PHP.MyName',
],
'Sniff in external standard with namespace prefix' => [
'fqnClass' => 'Vendor\\Package\\MyStandard\\Sniffs\\Category\\AnalyzeMeSniff',
'expected' => 'MyStandard.Category.AnalyzeMe',
],
'Test in external standard with namespace prefix' => [
'fqnClass' => 'Vendor\\Package\\MyStandard\\Tests\\Category\\AnalyzeMeUnitTest',
'expected' => 'MyStandard.Category.AnalyzeMe',
],
];

}//end dataGetSniffCode()


}//end class

0 comments on commit c75c7d2

Please sign in to comment.