* @copyright 2019 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/
namespace PHP_CodeSniffer\Tests\Core\Tokenizers\PHP;
use PHP_CodeSniffer\Tests\Core\Tokenizers\AbstractTokenizerTestCase;
final class AnonClassParenthesisOwnerTest extends AbstractTokenizerTestCase
{
/**
* Test that anonymous class tokens without parenthesis do not get assigned a parenthesis owner.
*
* @param string $testMarker The comment which prefaces the target token in the test file.
*
* @dataProvider dataAnonClassNoParentheses
* @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
*
* @return void
*/
public function testAnonClassNoParentheses($testMarker)
{
$tokens = $this->phpcsFile->getTokens();
$anonClass = $this->getTargetToken($testMarker, T_ANON_CLASS);
$this->assertArrayNotHasKey('parenthesis_owner', $tokens[$anonClass]);
$this->assertArrayNotHasKey('parenthesis_opener', $tokens[$anonClass]);
$this->assertArrayNotHasKey('parenthesis_closer', $tokens[$anonClass]);
}//end testAnonClassNoParentheses()
/**
* Test that the next open/close parenthesis after an anonymous class without parenthesis
* do not get assigned the anonymous class as a parenthesis owner.
*
* @param string $testMarker The comment which prefaces the target token in the test file.
*
* @dataProvider dataAnonClassNoParentheses
* @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
*
* @return void
*/
public function testAnonClassNoParenthesesNextOpenClose($testMarker)
{
$tokens = $this->phpcsFile->getTokens();
$function = $this->getTargetToken($testMarker, T_FUNCTION);
$opener = $this->getTargetToken($testMarker, T_OPEN_PARENTHESIS);
$this->assertArrayHasKey('parenthesis_owner', $tokens[$opener]);
$this->assertSame($function, $tokens[$opener]['parenthesis_owner']);
$closer = $this->getTargetToken($testMarker, T_CLOSE_PARENTHESIS);
$this->assertArrayHasKey('parenthesis_owner', $tokens[$closer]);
$this->assertSame($function, $tokens[$closer]['parenthesis_owner']);
}//end testAnonClassNoParenthesesNextOpenClose()
/**
* Data provider.
*
* @see testAnonClassNoParentheses()
* @see testAnonClassNoParenthesesNextOpenClose()
*
* @return array