|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Tests the tokenization of explicit octal notation to PHP < 8.1. |
| 4 | + * |
| 5 | + * @author Mark Baker <mark@demon-angel.eu> |
| 6 | + * @copyright 2019 Squiz Pty Ltd (ABN 77 084 670 600) |
| 7 | + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence |
| 8 | + */ |
| 9 | + |
| 10 | +namespace PHP_CodeSniffer\Tests\Core\Tokenizer; |
| 11 | + |
| 12 | +use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; |
| 13 | + |
| 14 | +class ExplicitOctalNotationTest extends AbstractMethodUnitTest |
| 15 | +{ |
| 16 | + |
| 17 | + |
| 18 | + /** |
| 19 | + * Test that explicitly-defined octal values are tokenized as a single number and not as a number and a string. |
| 20 | + * |
| 21 | + * @param array $testData The data required for the specific test case. |
| 22 | + * |
| 23 | + * @dataProvider dataExplicitOctalNotation |
| 24 | + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize |
| 25 | + * |
| 26 | + * @return void |
| 27 | + */ |
| 28 | + public function testExplicitOctalNotation($testData) |
| 29 | + { |
| 30 | + $tokens = self::$phpcsFile->getTokens(); |
| 31 | + |
| 32 | + $number = $this->getTargetToken($testData['marker'], [T_LNUMBER, T_DNUMBER, T_STRING]); |
| 33 | + |
| 34 | + $this->assertSame(constant($testData['type']), $tokens[$number]['code']); |
| 35 | + $this->assertSame($testData['type'], $tokens[$number]['type']); |
| 36 | + $this->assertSame($testData['value'], $tokens[$number]['content']); |
| 37 | + |
| 38 | + }//end testExplicitOctalNotation() |
| 39 | + |
| 40 | + |
| 41 | + /** |
| 42 | + * Data provider. |
| 43 | + * |
| 44 | + * @see testExplicitOctalNotation() |
| 45 | + * |
| 46 | + * @return array |
| 47 | + */ |
| 48 | + public function dataExplicitOctalNotation() |
| 49 | + { |
| 50 | + return [ |
| 51 | + [ |
| 52 | + [ |
| 53 | + 'marker' => '/* testExplicitOctal declaration */', |
| 54 | + 'type' => 'T_LNUMBER', |
| 55 | + 'value' => '0o137041', |
| 56 | + ], |
| 57 | + ], |
| 58 | + ]; |
| 59 | + |
| 60 | + }//end dataExplicitOctalNotation() |
| 61 | + |
| 62 | + |
| 63 | +}//end class |
0 commit comments