TASK: Update to latest TypoScript tokenizer

* As official project does no longer modify the file to tokenize.
* Add tests to test integration.
This commit is contained in:
Daniel Siepmann 2017-04-09 20:14:16 +02:00
parent 6528c391b2
commit a16ae7b8d4
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
5 changed files with 221 additions and 9 deletions

View file

@ -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.*"
},

View file

@ -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] = [

View file

@ -0,0 +1,64 @@
<?php
namespace Typo3Update\Tests\CodeSniffer\Tokenizers;
/*
* Copyright (C) 2017 Daniel Siepmann <coding@daniel-siepmann.de>
*
* 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.'
);
}
}

View file

@ -0,0 +1,6 @@
# Comment
plugin {
tx_example {
settings = TEST
}
}

View file

@ -0,0 +1,148 @@
<?php
return [
0 => 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' => '
',
),
];