11<?php
22/**
3- * Tests the tokenization of goto declarations and statements .
3+ * Tests the tokenization of heredoc/nowdoc closer tokens .
44 *
55 * @author Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl>
66 * @copyright 2020 Squiz Pty Ltd (ABN 77 084 670 600)
99
1010namespace PHP_CodeSniffer \Tests \Core \Tokenizer ;
1111
12- use PHP_CodeSniffer \Config ;
13- use PHP_CodeSniffer \Ruleset ;
14- use PHP_CodeSniffer \Files \DummyFile ;
1512use PHP_CodeSniffer \Tests \Core \AbstractMethodUnitTest ;
1613
1714/**
@@ -23,44 +20,11 @@ final class HeredocNowdocCloserTest extends AbstractMethodUnitTest
2320{
2421
2522
26- /**
27- * Initialize & tokenize \PHP_CodeSniffer\Files\File with code from the test case file.
28- *
29- * {@internal This is a near duplicate of the original method. Only difference is that
30- * tab replacement is enabled for this test.}
31- *
32- * @beforeClass
33- *
34- * @return void
35- */
36- public static function initializeFile ()
37- {
38- $ config = new Config ();
39- $ config ->standards = ['PSR1 ' ];
40- $ config ->tabWidth = 4 ;
41-
42- $ ruleset = new Ruleset ($ config );
43-
44- // Default to a file with the same name as the test class. Extension is property based.
45- $ relativeCN = str_replace (__NAMESPACE__ , '' , get_called_class ());
46- $ relativePath = str_replace ('\\' , DIRECTORY_SEPARATOR , $ relativeCN );
47- $ pathToTestFile = realpath (__DIR__ ).$ relativePath .'. ' .static ::$ fileExtension ;
48-
49- // Make sure the file gets parsed correctly based on the file type.
50- $ contents = 'phpcs_input_file: ' .$ pathToTestFile .PHP_EOL ;
51- $ contents .= file_get_contents ($ pathToTestFile );
52-
53- self ::$ phpcsFile = new DummyFile ($ contents , $ ruleset , $ config );
54- self ::$ phpcsFile ->process ();
55-
56- }//end initializeFile()
57-
58-
5923 /**
6024 * Verify that leading (indent) whitespace in a heredoc/nowdoc closer token get the tab replacement treatment.
6125 *
62- * @param string $testMarker The comment prefacing the target token.
63- * @param array $expected Expectations for the token array.
26+ * @param string $testMarker The comment prefacing the target token.
27+ * @param array<string, int|string|null> $expected Expectations for the token array.
6428 *
6529 * @dataProvider dataHeredocNowdocCloserTabReplacement
6630 * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
@@ -91,52 +55,52 @@ public function testHeredocNowdocCloserTabReplacement($testMarker, $expected)
9155 *
9256 * @see testHeredocNowdocCloserTabReplacement()
9357 *
94- * @return array
58+ * @return array<string, array<string, string|array<string, int|string|null>>>
9559 */
9660 public static function dataHeredocNowdocCloserTabReplacement ()
9761 {
9862 return [
99- [
63+ ' Heredoc closer without indent ' => [
10064 'testMarker ' => '/* testHeredocCloserNoIndent */ ' ,
10165 'expected ' => [
10266 'length ' => 3 ,
10367 'content ' => 'EOD ' ,
10468 'orig_content ' => null ,
10569 ],
10670 ],
107- [
71+ ' Nowdoc closer without indent ' => [
10872 'testMarker ' => '/* testNowdocCloserNoIndent */ ' ,
10973 'expected ' => [
11074 'length ' => 3 ,
11175 'content ' => 'EOD ' ,
11276 'orig_content ' => null ,
11377 ],
11478 ],
115- [
79+ ' Heredoc closer with indent, spaces ' => [
11680 'testMarker ' => '/* testHeredocCloserSpaceIndent */ ' ,
11781 'expected ' => [
11882 'length ' => 7 ,
11983 'content ' => ' END ' ,
12084 'orig_content ' => null ,
12185 ],
12286 ],
123- [
87+ ' Nowdoc closer with indent, spaces ' => [
12488 'testMarker ' => '/* testNowdocCloserSpaceIndent */ ' ,
12589 'expected ' => [
12690 'length ' => 8 ,
12791 'content ' => ' END ' ,
12892 'orig_content ' => null ,
12993 ],
13094 ],
131- [
95+ ' Heredoc closer with indent, tabs ' => [
13296 'testMarker ' => '/* testHeredocCloserTabIndent */ ' ,
13397 'expected ' => [
13498 'length ' => 8 ,
13599 'content ' => ' END ' ,
136100 'orig_content ' => ' END ' ,
137101 ],
138102 ],
139- [
103+ ' Nowdoc closer with indent, tabs ' => [
140104 'testMarker ' => '/* testNowdocCloserTabIndent */ ' ,
141105 'expected ' => [
142106 'length ' => 7 ,
0 commit comments