diff --git a/composer.json b/composer.json index 0db31eb..4d08966 100644 --- a/composer.json +++ b/composer.json @@ -11,14 +11,8 @@ "src/CodeSniffer/Tokenizers/TypoScript.php" ] }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/DanielSiepmann/typo3-typoscript-parser" - } - ], "require": { - "helmich/typo3-typoscript-parser": "dev-feature/allow-eol-handling", + "helmich/typo3-typoscript-parser": "1.1.*", "squizlabs/php_codesniffer": "2.8.*", "symfony/yaml": "3.2.*" }, diff --git a/src/CodeSniffer/Tokenizers/TypoScript.php b/src/CodeSniffer/Tokenizers/TypoScript.php index a6b8670..8130faf 100644 --- a/src/CodeSniffer/Tokenizers/TypoScript.php +++ b/src/CodeSniffer/Tokenizers/TypoScript.php @@ -41,10 +41,10 @@ class PHP_CodeSniffer_Tokenizers_TYPOSCRIPT * * @return array */ - public function tokenizeString($string, $eolChar = '\n') + public function tokenizeString($string, $eolChar = "\n") { $finalTokens = []; - $tokenizer = new Tokenizer($eolChar, false); + $tokenizer = new Tokenizer($eolChar); foreach ($tokenizer->tokenizeString($string) as $stackPtr => $token) { $finalTokens[$stackPtr] = [ diff --git a/tests/CodeSniffer/Tokenizers/TypoScriptTest.php b/tests/CodeSniffer/Tokenizers/TypoScriptTest.php new file mode 100644 index 0000000..51ec788 --- /dev/null +++ b/tests/CodeSniffer/Tokenizers/TypoScriptTest.php @@ -0,0 +1,64 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use PHPUnit\Framework\TestCase; + +/** + * Test TypoScript tokenizer. + */ +class TypoScriptTest extends TestCase +{ + /** + * @test + */ + public function callingTokenizerWorksAsExpected() + { + $subject = new \PHP_CodeSniffer_Tokenizers_TYPOSCRIPT(); + $resultFile = implode(DIRECTORY_SEPARATOR, [ + __DIR__, + '..', + '..', + 'Fixtures', + 'CodeSniffer', + 'Tokenizers', + 'TypoScript', + 'expected.php', + ]); + $testFile = implode(DIRECTORY_SEPARATOR, [ + __DIR__, + '..', + '..', + 'Fixtures', + 'CodeSniffer', + 'Tokenizers', + 'TypoScript', + 'example.ts', + ]); + + $this->assertEquals( + require $resultFile, + $subject->tokenizeString(file_get_contents($testFile), "\n"), + 'Did not get expected tokens.' + ); + } +} diff --git a/tests/Fixtures/CodeSniffer/Tokenizers/TypoScript/example.ts b/tests/Fixtures/CodeSniffer/Tokenizers/TypoScript/example.ts new file mode 100644 index 0000000..dee12f7 --- /dev/null +++ b/tests/Fixtures/CodeSniffer/Tokenizers/TypoScript/example.ts @@ -0,0 +1,6 @@ +# Comment +plugin { + tx_example { + settings = TEST + } +} diff --git a/tests/Fixtures/CodeSniffer/Tokenizers/TypoScript/expected.php b/tests/Fixtures/CodeSniffer/Tokenizers/TypoScript/expected.php new file mode 100644 index 0000000..196ca8e --- /dev/null +++ b/tests/Fixtures/CodeSniffer/Tokenizers/TypoScript/expected.php @@ -0,0 +1,148 @@ + array ( + 'code' => 'COMMENT', + 'type' => 'COMMENT', + 'line' => 1, + 'content' => '# Comment', +), +1 => array ( + 'code' => 'WS', + 'type' => 'WS', + 'line' => 1, + 'content' => ' +', +), +2 => array ( + 'code' => 'OBJ_IDENT', + 'type' => 'OBJ_IDENT', + 'line' => 2, + 'content' => 'plugin', +), +3 => array ( + 'code' => 'WS', + 'type' => 'WS', + 'line' => 2, + 'content' => ' ', +), +4 => array ( + 'code' => 'BR_OPEN', + 'type' => 'BR_OPEN', + 'line' => 2, + 'content' => '{', +), +5 => array ( + 'code' => 'WS', + 'type' => 'WS', + 'line' => 2, + 'content' => ' +', +), +6 => array ( + 'code' => 'WS', + 'type' => 'WS', + 'line' => 3, + 'content' => ' ', +), +7 => array ( + 'code' => 'OBJ_IDENT', + 'type' => 'OBJ_IDENT', + 'line' => 3, + 'content' => 'tx_example', +), +8 => array ( + 'code' => 'WS', + 'type' => 'WS', + 'line' => 3, + 'content' => ' ', +), +9 => array ( + 'code' => 'BR_OPEN', + 'type' => 'BR_OPEN', + 'line' => 3, + 'content' => '{', +), +10 => array ( + 'code' => 'WS', + 'type' => 'WS', + 'line' => 3, + 'content' => ' +', +), +11 => array ( + 'code' => 'WS', + 'type' => 'WS', + 'line' => 4, + 'content' => ' ', +), +12 => array ( + 'code' => 'OBJ_IDENT', + 'type' => 'OBJ_IDENT', + 'line' => 4, + 'content' => 'settings', +), +13 => array ( + 'code' => 'WS', + 'type' => 'WS', + 'line' => 4, + 'content' => ' ', +), +14 => array ( + 'code' => 'OP_ASSIGN', + 'type' => 'OP_ASSIGN', + 'line' => 4, + 'content' => '=', +), +15 => array ( + 'code' => 'WS', + 'type' => 'WS', + 'line' => 4, + 'content' => ' ', +), +16 => array ( + 'code' => 'RVALUE', + 'type' => 'RVALUE', + 'line' => 4, + 'content' => 'TEST', +), +17 => array ( + 'code' => 'WS', + 'type' => 'WS', + 'line' => 4, + 'content' => ' +', +), +18 => array ( + 'code' => 'WS', + 'type' => 'WS', + 'line' => 5, + 'content' => ' ', +), +19 => array ( + 'code' => 'BR_CLOSE', + 'type' => 'BR_CLOSE', + 'line' => 5, + 'content' => '}', +), +20 => array ( + 'code' => 'WS', + 'type' => 'WS', + 'line' => 5, + 'content' => ' +', +), +21 => array ( + 'code' => 'BR_CLOSE', + 'type' => 'BR_CLOSE', + 'line' => 6, + 'content' => '}', +), +22 => array ( + 'code' => 'WS', + 'type' => 'WS', + 'line' => 6, + 'content' => ' +', +), +];