* @copyright 2022-2024 PHPCSStandards Contributors
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/
namespace PHP_CodeSniffer\Tests\Core\Files\File;
use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest;
/**
* Tests for the \PHP_CodeSniffer\Files\File:getDeclarationName method.
*
* @covers \PHP_CodeSniffer\Files\File::getDeclarationName
*/
final class GetDeclarationNameJSTest extends AbstractMethodUnitTest
{
/**
* The file extension of the test case file (without leading dot).
*
* @var string
*/
protected static $fileExtension = 'js';
/**
* Test receiving an expected exception when a non-supported token is passed.
*
* @return void
*/
public function testInvalidTokenPassed()
{
$this->expectRunTimeException('Token type "T_STRING" is not T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT or T_ENUM');
$target = $this->getTargetToken('/* testInvalidTokenPassed */', T_STRING);
self::$phpcsFile->getDeclarationName($target);
}//end testInvalidTokenPassed()
/**
* Test receiving "null" when passed an anonymous construct or in case of a parse error.
*
* @param string $testMarker The comment which prefaces the target token in the test file.
* @param int|string $targetType Token type of the token to get as stackPtr.
*
* @dataProvider dataGetDeclarationNameNull
*
* @return void
*/
public function testGetDeclarationNameNull($testMarker, $targetType)
{
$target = $this->getTargetToken($testMarker, $targetType);
$result = self::$phpcsFile->getDeclarationName($target);
$this->assertNull($result);
}//end testGetDeclarationNameNull()
/**
* Data provider.
*
* @see GetDeclarationNameTest::testGetDeclarationNameNull()
*
* @return array