* Dariusz Rumiński * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace PhpCsFixer\Tests\Tokenizer; use PhpCsFixer\Tests\TestCase; use PhpCsFixer\Tokenizer\CT; /** * @author Dariusz Rumiński * * @internal * * @covers \PhpCsFixer\Tokenizer\CT */ final class CTTest extends TestCase { public function testUniqueValues(): void { $constants = self::getConstants(); self::assertSame($constants, array_flip(array_flip($constants)), 'Values of CT::T_* constants must be unique.'); } /** * @dataProvider provideConstantsCases */ public function testHas(string $name, int $value): void { self::assertTrue(CT::has($value)); } public function testHasNotExists(): void { self::assertFalse(CT::has(123)); } /** * @dataProvider provideConstantsCases */ public function testGetName(string $name, int $value): void { self::assertSame('CT::'.$name, CT::getName($value)); } public function testGetNameNotExists(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('No custom token was found for "123".'); CT::getName(123); } /** * @dataProvider provideConstantsCases */ public function testConstants(string $name, int $value): void { self::assertGreaterThan(10_000, $value); self::assertFalse(\defined($name), 'The CT name must not use native T_* name.'); } /** * @return iterable */ public static function provideConstantsCases(): iterable { foreach (self::getConstants() as $name => $value) { yield [$name, $value]; } } /** * @return array */ private static function getConstants(): array { static $constants; if (null === $constants) { $reflection = new \ReflectionClass(CT::class); $constants = $reflection->getConstants(); } return $constants; } }