1
1
<?php
2
2
/**
3
- * Tests the tokenization of goto declarations and statements .
3
+ * Tests the tokenization of heredoc/nowdoc closer tokens .
4
4
*
5
5
* @author Juliette Reinders Folmer <[email protected] >
6
6
* @copyright 2020 Squiz Pty Ltd (ABN 77 084 670 600)
9
9
10
10
namespace PHP_CodeSniffer \Tests \Core \Tokenizer ;
11
11
12
- use PHP_CodeSniffer \Config ;
13
- use PHP_CodeSniffer \Ruleset ;
14
- use PHP_CodeSniffer \Files \DummyFile ;
15
12
use PHP_CodeSniffer \Tests \Core \AbstractMethodUnitTest ;
16
13
17
14
/**
@@ -23,44 +20,11 @@ final class HeredocNowdocCloserTest extends AbstractMethodUnitTest
23
20
{
24
21
25
22
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
-
59
23
/**
60
24
* Verify that leading (indent) whitespace in a heredoc/nowdoc closer token get the tab replacement treatment.
61
25
*
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.
64
28
*
65
29
* @dataProvider dataHeredocNowdocCloserTabReplacement
66
30
* @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
@@ -91,52 +55,52 @@ public function testHeredocNowdocCloserTabReplacement($testMarker, $expected)
91
55
*
92
56
* @see testHeredocNowdocCloserTabReplacement()
93
57
*
94
- * @return array
58
+ * @return array<string, array<string, string|array<string, int|string|null>>>
95
59
*/
96
60
public static function dataHeredocNowdocCloserTabReplacement ()
97
61
{
98
62
return [
99
- [
63
+ ' Heredoc closer without indent ' => [
100
64
'testMarker ' => '/* testHeredocCloserNoIndent */ ' ,
101
65
'expected ' => [
102
66
'length ' => 3 ,
103
67
'content ' => 'EOD ' ,
104
68
'orig_content ' => null ,
105
69
],
106
70
],
107
- [
71
+ ' Nowdoc closer without indent ' => [
108
72
'testMarker ' => '/* testNowdocCloserNoIndent */ ' ,
109
73
'expected ' => [
110
74
'length ' => 3 ,
111
75
'content ' => 'EOD ' ,
112
76
'orig_content ' => null ,
113
77
],
114
78
],
115
- [
79
+ ' Heredoc closer with indent, spaces ' => [
116
80
'testMarker ' => '/* testHeredocCloserSpaceIndent */ ' ,
117
81
'expected ' => [
118
82
'length ' => 7 ,
119
83
'content ' => ' END ' ,
120
84
'orig_content ' => null ,
121
85
],
122
86
],
123
- [
87
+ ' Nowdoc closer with indent, spaces ' => [
124
88
'testMarker ' => '/* testNowdocCloserSpaceIndent */ ' ,
125
89
'expected ' => [
126
90
'length ' => 8 ,
127
91
'content ' => ' END ' ,
128
92
'orig_content ' => null ,
129
93
],
130
94
],
131
- [
95
+ ' Heredoc closer with indent, tabs ' => [
132
96
'testMarker ' => '/* testHeredocCloserTabIndent */ ' ,
133
97
'expected ' => [
134
98
'length ' => 8 ,
135
99
'content ' => ' END ' ,
136
100
'orig_content ' => ' END ' ,
137
101
],
138
102
],
139
- [
103
+ ' Nowdoc closer with indent, tabs ' => [
140
104
'testMarker ' => '/* testNowdocCloserTabIndent */ ' ,
141
105
'expected ' => [
142
106
'length ' => 7 ,
0 commit comments