1<?php declare(strict_types=1); 2 3namespace PhpParser; 4 5class TokenTest extends \PHPUnit\Framework\TestCase { 6 public function testGetTokenName(): void { 7 $token = new Token(\ord(','), ','); 8 $this->assertSame(',', $token->getTokenName()); 9 $token = new Token(\T_WHITESPACE, ' '); 10 $this->assertSame('T_WHITESPACE', $token->getTokenName()); 11 } 12 13 public function testIs(): void { 14 $token = new Token(\ord(','), ','); 15 $this->assertTrue($token->is(\ord(','))); 16 $this->assertFalse($token->is(\ord(';'))); 17 $this->assertTrue($token->is(',')); 18 $this->assertFalse($token->is(';')); 19 $this->assertTrue($token->is([\ord(','), \ord(';')])); 20 $this->assertFalse($token->is([\ord('!'), \ord(';')])); 21 $this->assertTrue($token->is([',', ';'])); 22 $this->assertFalse($token->is(['!', ';'])); 23 } 24 25 /** @dataProvider provideTestIsIgnorable */ 26 public function testIsIgnorable(int $id, string $text, bool $isIgnorable): void { 27 $token = new Token($id, $text); 28 $this->assertSame($isIgnorable, $token->isIgnorable()); 29 } 30 31 public static function provideTestIsIgnorable() { 32 return [ 33 [\T_STRING, 'foo', false], 34 [\T_WHITESPACE, ' ', true], 35 [\T_COMMENT, '// foo', true], 36 [\T_DOC_COMMENT, '/** foo */', true], 37 [\T_OPEN_TAG, '<?php ', true], 38 ]; 39 } 40 41 public function testToString(): void { 42 $token = new Token(\ord(','), ','); 43 $this->assertSame(',', (string) $token); 44 $token = new Token(\T_STRING, 'foo'); 45 $this->assertSame('foo', (string) $token); 46 } 47} 48