9
9
10
10
namespace PHP_CodeSniffer \Tests \Core ;
11
11
12
+ use Exception ;
12
13
use PHP_CodeSniffer \Files \DummyFile ;
13
14
use PHP_CodeSniffer \Files \File ;
14
15
use PHP_CodeSniffer \Ruleset ;
@@ -110,6 +111,9 @@ public function getTargetToken($commentString, $tokenType, $tokenContent=null)
110
111
* @param string $tokenContent Optional. The token content for the target token.
111
112
*
112
113
* @return int
114
+ *
115
+ * @throws Exception When the test delimiter comment is not found.
116
+ * @throws Exception When the test target token is not found.
113
117
*/
114
118
public static function getTargetTokenFromFile (File $ phpcsFile , $ commentString , $ tokenType , $ tokenContent =null )
115
119
{
@@ -122,6 +126,12 @@ public static function getTargetTokenFromFile(File $phpcsFile, $commentString, $
122
126
$ commentString
123
127
);
124
128
129
+ if ($ comment === false ) {
130
+ throw new Exception (
131
+ sprintf ('Failed to find the test marker: %s in test case file %s ' , $ commentString , $ phpcsFile ->getFilename ())
132
+ );
133
+ }
134
+
125
135
$ tokens = $ phpcsFile ->getTokens ();
126
136
$ end = ($ start + 1 );
127
137
@@ -148,10 +158,10 @@ public static function getTargetTokenFromFile(File $phpcsFile, $commentString, $
148
158
if ($ target === false ) {
149
159
$ msg = 'Failed to find test target token for comment string: ' .$ commentString ;
150
160
if ($ tokenContent !== null ) {
151
- $ msg .= ' With token content: ' .$ tokenContent ;
161
+ $ msg .= ' with token content: ' .$ tokenContent ;
152
162
}
153
163
154
- self :: assertFalse ( true , $ msg );
164
+ throw new Exception ( $ msg );
155
165
}
156
166
157
167
return $ target ;
0 commit comments