Merge pull request #60 from DanielSiepmann/feature/update-typoscript-dependency
TASK: Update to latest TypoScript tokenizer
This commit is contained in:
commit
87a3cc071a
5 changed files with 221 additions and 9 deletions
|
@ -15,14 +15,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.*"
|
||||
},
|
||||
|
|
|
@ -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] = [
|
||||
|
|
64
tests/CodeSniffer/Tokenizers/TypoScriptTest.php
Normal file
64
tests/CodeSniffer/Tokenizers/TypoScriptTest.php
Normal 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.'
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
# Comment
|
||||
plugin {
|
||||
tx_example {
|
||||
settings = TEST
|
||||
}
|
||||
}
|
148
tests/Fixtures/CodeSniffer/Tokenizers/TypoScript/expected.php
Normal file
148
tests/Fixtures/CodeSniffer/Tokenizers/TypoScript/expected.php
Normal 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' => '
|
||||
',
|
||||
),
|
||||
];
|
Loading…
Reference in a new issue