Arbit - project tracking

PHP Depend

History

Diff

1035 1036 /tests/PHP/Depend/_code/code/ASTString/testBacktickExpressionContainsTwoChildNodes.php
2 +<?php
3 +function testBacktickExpressionContainsTwoChildNodes() {
4 + $expr = `ls $dir`;
5 +}
1035 1036 /tests/PHP/Depend/_code/code/ASTString/testBacktickExpressionContainsExpectedCompoundVariable.php
2 +<?php
3 +function testBacktickExpressionContainsExpectedCompoundVariable() {
4 + $expr = `${$foo * $bar}`;
5 +}
1035 1036 /tests/PHP/Depend/Code/ASTStringTest.php
50 50 require_once dirname(__FILE__) . '/ASTNodeTest.php';
51 51
52 52 require_once 'PHP/Depend/Code/ASTString.php';
53 +require_once 'PHP/Depend/Code/ASTCompoundVariable.php';
53 54
54 55 /**
55 56 * Test case for the {@link PHP_Depend_Code_ASTString} class.
70 71 *
71 72 * @return void
72 73 * @covers PHP_Depend_Code_ASTString
74 + * @covers PHP_Depend_Parser::_parseString
73 75 * @covers PHP_Depend_Parser::_parseLiteralOrString
74 76 * @group pdepend
75 77 * @group pdepend::ast
85 87 *
86 88 * @return void
87 89 * @covers PHP_Depend_Code_ASTString
90 + * @covers PHP_Depend_Parser::_parseString
88 91 * @covers PHP_Depend_Parser::_parseLiteralOrString
89 92 * @group pdepend
90 93 * @group pdepend::ast
96 99 }
97 100
98 101 /**
102 + * testBacktickExpressionContainsTwoChildNodes
103 + *
104 + * @return void
105 + * @covers PHP_Depend_Code_ASTString
106 + * @covers PHP_Depend_Parser::_parseString
107 + * @covers PHP_Depend_Parser::_parseLiteralOrString
108 + * @group pdepend
109 + * @group pdepend::ast
110 + */
111 + public function testBacktickExpressionContainsTwoChildNodes()
112 + {
113 + $string = $this->_getFirstStringInFunction(__METHOD__);
114 + $this->assertEquals(2, count($string->getChildren()));
115 + }
116 +
117 + /**
118 + * testBacktickExpressionContainsExpectedCompoundVariable
119 + *
120 + * @return void
121 + * @covers PHP_Depend_Code_ASTString
122 + * @covers PHP_Depend_Parser::_parseString
123 + * @covers PHP_Depend_Parser::_parseLiteralOrString
124 + * @group pdepend
125 + * @group pdepend::ast
126 + */
127 + public function testBacktickExpressionContainsExpectedCompoundVariable()
128 + {
129 + $string = $this->_getFirstStringInFunction(__METHOD__);
130 + $this->assertType(PHP_Depend_Code_ASTCompoundVariable::CLAZZ, $string->getChild(0));
131 + }
132 +
133 + /**
99 134 * Tests that an invalid literal results in the expected exception.
100 135 *
101 136 * @return void
1035 1036 /tests/PHP/Depend/Tokenizer/InternalTest.php
70 70 * Tests the tokenizer with a source file that contains only classes.
71 71 *
72 72 * @return void
73 - * @group tokenizer
73 + * @covers PHP_Depend_Tokenizer_Internal
74 + * @group pdepend
75 + * @group pdepend::tokenizer
76 + * @group unittest
74 77 */
75 78 public function testInternalWithClasses()
76 79 {
78 81 $tokenizer = new PHP_Depend_Tokenizer_Internal();
79 82 $tokenizer->setSourceFile($sourceFile);
80 83
81 - $tokens = array(
84 + $expected = array(
82 85 PHP_Depend_TokenizerI::T_OPEN_TAG,
83 86 PHP_Depend_TokenizerI::T_DOC_COMMENT,
84 87 PHP_Depend_TokenizerI::T_ABSTRACT,
115 118 PHP_Depend_TokenizerI::T_CURLY_BRACE_CLOSE
116 119 );
117 120
118 - $this->assertEquals($sourceFile, (string) $tokenizer->getSourceFile());
119 -
120 - while (($token = $tokenizer->next()) !== PHP_Depend_TokenizerI::T_EOF) {
121 - $this->assertEquals($token->type, array_shift($tokens));
121 + $actual = array();
122 + while (is_object($token = $tokenizer->next())) {
123 + $actual[] = $token->type;
122 124 }
123 125
124 - $this->assertEquals(0, count($tokens));
126 + $this->assertEquals($expected, $actual);
125 127 }
126 128
127 129 /**
129 131 * classes and functions.
130 132 *
131 133 * @return void
132 - * @group tokenizer
134 + * @covers PHP_Depend_Tokenizer_Internal
135 + * @group pdepend
136 + * @group pdepend::tokenizer
137 + * @group unittest
133 138 */
134 139 public function testInternalWithMixedContent()
135 140 {
137 142 $tokenizer = new PHP_Depend_Tokenizer_Internal();
138 143 $tokenizer->setSourceFile($sourceFile);
139 144
140 - $tokens = array(
145 + $expected = array(
141 146 array(PHP_Depend_TokenizerI::T_OPEN_TAG, 1),
142 147 array(PHP_Depend_TokenizerI::T_COMMENT, 2),
143 148 array(PHP_Depend_TokenizerI::T_FUNCTION, 5),
166 171 array(PHP_Depend_TokenizerI::T_CLOSE_TAG, 16)
167 172 );
168 173
169 - $this->assertEquals($sourceFile, (string) $tokenizer->getSourceFile());
170 -
171 - while (($token = $tokenizer->next()) !== PHP_Depend_TokenizerI::T_EOF) {
172 - list($tok, $line) = array_shift($tokens);
173 - $this->assertEquals($tok, $token->type);
174 - $this->assertEquals($line, $token->startLine);
174 + $actual = array();
175 + while (is_object($token = $tokenizer->next())) {
176 + $actual[] = array($token->type, $token->startLine);
175 177 }
176 -
177 - $this->assertEquals(0, count($tokens));
178 +
179 + $this->assertEquals($expected, $actual);
178 180 }
179 181
180 182 /**
182 184 * token.
183 185 *
184 186 * @return void
185 - * @group tokenizer
187 + * @covers PHP_Depend_Tokenizer_Internal
188 + * @group pdepend
189 + * @group pdepend::tokenizer
190 + * @group unittest
186 191 */
187 192 public function testInternalReturnsBOFTokenForPrevCall()
188 193 {
197 202 * Tests the tokenizer with a combination of procedural code and functions.
198 203 *
199 204 * @return void
200 - * @group tokenizer
205 + * @covers PHP_Depend_Tokenizer_Internal
206 + * @group pdepend
207 + * @group pdepend::tokenizer
208 + * @group unittest
201 209 */
202 210 public function testInternalWithProceduralCodeAndFunction()
203 211 {
205 213 $tokenizer = new PHP_Depend_Tokenizer_Internal();
206 214 $tokenizer->setSourceFile($sourceFile);
207 215
208 - $tokens = array(
216 + $expected = array(
209 217 PHP_Depend_TokenizerI::T_OPEN_TAG,
210 218 PHP_Depend_TokenizerI::T_FUNCTION,
211 219 PHP_Depend_TokenizerI::T_STRING,
241 249 PHP_Depend_TokenizerI::T_CLOSE_TAG
242 250 );
243 251
244 - $this->assertEquals($sourceFile, (string) $tokenizer->getSourceFile());
245 -
246 - while ($tokenizer->peek() !== PHP_Depend_TokenizerI::T_EOF) {
247 - $token = $tokenizer->next();
248 - $this->assertEquals(array_shift($tokens), $token->type);
252 + $actual = array();
253 + while (is_object($token = $tokenizer->next())) {
254 + $actual[] = $token->type;
249 255 }
250 256
251 - $this->assertEquals(0, count($tokens));
257 + $this->assertEquals($expected, $actual);
252 258 }
253 259
254 260 /**
255 261 * Test case for undetected static method call added.
256 262 *
257 263 * @return void
258 - * @group tokenizer
264 + * @covers PHP_Depend_Tokenizer_Internal
265 + * @group pdepend
266 + * @group pdepend::tokenizer
267 + * @group unittest
259 268 */
260 269 public function testInternalStaticCallBug01()
261 270 {
263 272 $tokenizer = new PHP_Depend_Tokenizer_Internal();
264 273 $tokenizer->setSourceFile($sourceFile);
265 274
266 - $tokens = array(
275 + $expected = array(
267 276 PHP_Depend_TokenizerI::T_OPEN_TAG,
268 277 PHP_Depend_TokenizerI::T_DOC_COMMENT,
269 278 PHP_Depend_TokenizerI::T_CLASS,
285 294 PHP_Depend_TokenizerI::T_CURLY_BRACE_CLOSE,
286 295 );
287 296
288 - while (($token = $tokenizer->next()) !== PHP_Depend_TokenizerI::T_EOF) {
289 - $this->assertEquals(array_shift($tokens), $token->type);
297 + $actual = array();
298 + while (is_object($token = $tokenizer->next())) {
299 + $actual[] = $token->type;
290 300 }
291 301
292 - $this->assertEquals(0, count($tokens));
302 + $this->assertEquals($expected, $actual);
293 303 }
294 304
295 305 /**
306 316 * http://bugs.xplib.de/index.php?do=details&task_id=9&project=3
307 317 *
308 318 * @return void
309 - * @group tokenizer
319 + * @covers PHP_Depend_Tokenizer_Internal
320 + * @group pdepend
321 + * @group pdepend::tokenizer
322 + * @group unittest
310 323 */
311 324 public function testInternalDollarSyntaxBug09()
312 325 {
314 327 $tokenizer = new PHP_Depend_Tokenizer_Internal();
315 328 $tokenizer->setSourceFile($sourceFile);
316 329
317 - $tokens = array(
330 + $expected = array(
318 331 PHP_Depend_TokenizerI::T_OPEN_TAG,
319 332 PHP_Depend_TokenizerI::T_DOC_COMMENT,
320 333 PHP_Depend_TokenizerI::T_CLASS,
338 351 PHP_Depend_TokenizerI::T_CURLY_BRACE_CLOSE,
339 352 );
340 353
341 - while (($token = $tokenizer->next()) !== PHP_Depend_TokenizerI::T_EOF) {
342 - $this->assertEquals(array_shift($tokens), $token->type);
354 + $actual = array();
355 + while (is_object($token = $tokenizer->next())) {
356 + $actual[] = $token->type;
343 357 }
344 358
345 - $this->assertEquals(0, count($tokens));
359 + $this->assertEquals($expected, $actual);
346 360 }
347 361
348 362 /**
349 363 * Test case for the inline html bug.
350 364 *
351 365 * @return void
352 - * @group tokenizer
366 + * @covers PHP_Depend_Tokenizer_Internal
367 + * @group pdepend
368 + * @group pdepend::tokenizer
369 + * @group unittest
353 370 */
354 371 public function testTokenizerWithInlineHtmlBug24()
355 372 {
357 374 $tokenizer = new PHP_Depend_Tokenizer_Internal();
358 375 $tokenizer->setSourceFile($sourceFile);
359 376
360 - $tokens = array(
377 + $expected = array(
361 378 array(PHP_Depend_TokenizerI::T_OPEN_TAG, 1),
362 379 array(PHP_Depend_TokenizerI::T_CLASS, 2),
363 380 array(PHP_Depend_TokenizerI::T_STRING, 2),
395 412 array(PHP_Depend_TokenizerI::T_CURLY_BRACE_CLOSE, 17),
396 413 );
397 414
398 - while (($token = $tokenizer->next()) !== PHP_Depend_TokenizerI::T_EOF) {
399 - $expected = array_shift($tokens);
400 -
401 - $this->assertEquals($expected[0], $token->type);
402 - $this->assertEquals($expected[1], $token->startLine);
415 + $actual = array();
416 + while (is_object($token = $tokenizer->next())) {
417 + $actual[] = array($token->type, $token->startLine);
403 418 }
404 419
405 - $this->assertEquals(0, count($tokens));
420 + $this->assertSame($expected, $actual);
406 421 }
407 422
408 423 /**
410 425 * this bug only occures for PHP versions < 5.3.0alpha3.
411 426 *
412 427 * @return void
413 - * @group tokenizer
428 + * @covers PHP_Depend_Tokenizer_Internal
429 + * @group pdepend
430 + * @group pdepend::tokenizer
431 + * @group unittest
414 432 */
415 433 public function testTokenizerHandlesBackslashInStringCorrectBug84()
416 434 {
422 440 $tokenizer = new PHP_Depend_Tokenizer_Internal();
423 441 $tokenizer->setSourceFile($sourceFile);
424 442
425 - $tokens = array(
443 + $expected = array(
426 444 array(PHP_Depend_TokenizerI::T_OPEN_TAG, 1),
427 445 array(PHP_Depend_TokenizerI::T_VARIABLE, 2),
428 446 array(PHP_Depend_TokenizerI::T_EQUAL, 2),
431 449 array(PHP_Depend_TokenizerI::T_CLOSE_TAG, 3),
432 450 );
433 451
434 - while (($token = $tokenizer->next()) !== PHP_Depend_TokenizerI::T_EOF) {
435 - $expected = array_shift($tokens);
436 -
437 - $this->assertEquals($expected[0], $token->type);
438 - $this->assertEquals($expected[1], $token->startLine);
452 + $actual = array();
453 + while (is_object($token = $tokenizer->next())) {
454 + $actual[] = array($token->type, $token->startLine);
439 455 }
440 456
441 - $this->assertEquals(0, count($tokens));
457 + $this->assertSame($expected, $actual);
442 458 }
443 459
444 460 /**
445 461 * Tests the tokenizers column calculation implementation.
446 462 *
447 463 * @return void
448 - * @group tokenizer
464 + * @covers PHP_Depend_Tokenizer_Internal
465 + * @group pdepend
466 + * @group pdepend::tokenizer
467 + * @group unittest
449 468 */
450 469 public function testTokenizerCalculatesCorrectColumnForInlinePhpIssue88()
451 470 {
453 472 $tokenizer = new PHP_Depend_Tokenizer_Internal();
454 473 $tokenizer->setSourceFile($sourceFile);
455 474
456 - $tokens = array(
475 + $expected = array(
457 476 array(PHP_Depend_ConstantsI::T_NO_PHP, '<html>
458 477 <head>
459 478 <title>', 1, 3, 1, 15),
474 493 </html>', 7, 8, 1, 7),
475 494 );
476 495
477 - while (($token = $tokenizer->next()) !== PHP_Depend_TokenizerI::T_EOF) {
478 - $expected = array_shift($tokens);
479 -
480 - $this->assertEquals($expected[0], $token->type);
481 - $this->assertEquals($expected[1], $token->image);
482 - $this->assertEquals($expected[2], $token->startLine);
483 - $this->assertEquals($expected[3], $token->endLine);
484 - $this->assertEquals($expected[4], $token->startColumn);
485 - $this->assertEquals($expected[5], $token->endColumn);
496 + $actual = array();
497 + while (is_object($token = $tokenizer->next())) {
498 + $actual[] = array(
499 + $token->type,
500 + $token->image,
501 + $token->startLine,
502 + $token->endLine,
503 + $token->startColumn,
504 + $token->endColumn
505 + );
486 506 }
487 507
488 - $this->assertEquals(0, count($tokens));
508 + $this->assertSame($expected, $actual);
489 509 }
490 510
491 511 /**
492 512 * Tests the tokenizers column calculation implementation.
493 513 *
494 514 * @return void
495 - * @group tokenizer
515 + * @covers PHP_Depend_Tokenizer_Internal
516 + * @group pdepend
517 + * @group pdepend::tokenizer
518 + * @group unittest
496 519 */
497 520 public function testTokenizerCalculatesCorrectColumnForInlinePhpInTextIssue88()
498 521 {
500 523 $tokenizer = new PHP_Depend_Tokenizer_Internal();
501 524 $tokenizer->setSourceFile($sourceFile);
502 525
503 - $tokens = array(
526 + $expected = array(
504 527 array(PHP_Depend_ConstantsI::T_NO_PHP, 'Hello', 1, 1, 1, 5),
505 528 array(PHP_Depend_ConstantsI::T_OPEN_TAG, '<?php', 1, 1, 7, 11),
506 529 array(PHP_Depend_ConstantsI::T_ECHO, 'echo', 1, 1, 13, 16),
519 542 Manuel', 3, 5, 61, 6),
520 543 );
521 544
522 - while (($token = $tokenizer->next()) !== PHP_Depend_TokenizerI::T_EOF) {
523 - $expected = array_shift($tokens);
524 -
525 - $this->assertEquals($expected[0], $token->type);
526 - $this->assertEquals($expected[1], $token->image);
527 - $this->assertEquals($expected[2], $token->startLine);
528 - $this->assertEquals($expected[3], $token->endLine);
529 - $this->assertEquals($expected[4], $token->startColumn);
530 - $this->assertEquals($expected[5], $token->endColumn);
545 + $actual = array();
546 + while (is_object($token = $tokenizer->next())) {
547 + $actual[] = array(
548 + $token->type,
549 + $token->image,
550 + $token->startLine,
551 + $token->endLine,
552 + $token->startColumn,
553 + $token->endColumn
554 + );
531 555 }
532 556
533 - $this->assertEquals(0, count($tokens));
557 + $this->assertSame($expected, $actual);
534 558 }
535 559 }
1035 1036 /tests/PHP/Depend/Tokenizer/PHP53NamespaceHelperTest.php
70 70 * namespace separators.
71 71 *
72 72 * @return void
73 - * @group tokenizer
73 + * @covers PHP_Depend_Tokenizer_PHP53NamespaceHelper
74 + * @group pdepend
75 + * @group pdepend::tokenizer
76 + * @group unittest
74 77 */
75 78 public function testHelperCreatesExpectedTokenArrayWithBackslash()
76 79 {
103 106 * namespace separators.
104 107 *
105 108 * @return void
106 - * @group tokenizer
109 + * @covers PHP_Depend_Tokenizer_PHP53NamespaceHelper
110 + * @group pdepend
111 + * @group pdepend::tokenizer
112 + * @group unittest
107 113 */
108 114 public function testHelperCreatesExpectedTokenArrayWithNamespacedAllocation()
109 115 {
135 141 * namespace separators.
136 142 *
137 143 * @return void
138 - * @group tokenizer
144 + * @covers PHP_Depend_Tokenizer_PHP53NamespaceHelper
145 + * @group pdepend
146 + * @group pdepend::tokenizer
147 + * @group unittest
139 148 */
140 149 public function testHelperCreatesExpectedTokenArrayWithNamespacedQualifiedName()
141 150 {
164 173 * Tests that the helper ignores backslashes used as escape character.
165 174 *
166 175 * @return void
167 - * @group tokenizer
176 + * @covers PHP_Depend_Tokenizer_PHP53NamespaceHelper
177 + * @group pdepend
178 + * @group pdepend::tokenizer
179 + * @group unittest
168 180 */
169 181 public function testHelperIgnoresBackslashAsDoubleQuoteEscapeCharacter()
170 182 {
188 200 * Tests that the helper ignores backslashes used as escape character.
189 201 *
190 202 * @return void
191 - * @group tokenizer
203 + * @covers PHP_Depend_Tokenizer_PHP53NamespaceHelper
204 + * @group pdepend
205 + * @group pdepend::tokenizer
206 + * @group unittest
192 207 */
193 208 public function testHelperIgnoresBackslashAsSignleQuoteEscapeCharacter()
194 209 {
212 227 * Tests that the helper ignores a class name in a string.
213 228 *
214 229 * @return void
215 - * @group tokenizer
230 + * @covers PHP_Depend_Tokenizer_PHP53NamespaceHelper
231 + * @group pdepend
232 + * @group pdepend::tokenizer
233 + * @group unittest
216 234 */
217 235 public function testHelperIgnoresQualifiedClassNameInDoubleQuotedString()
218 236 {
1035 1036 /PHP/Depend/Tokenizer/Internal.php
69 69 class PHP_Depend_Tokenizer_Internal
70 70 implements PHP_Depend_TokenizerI
71 71 {
72 + protected static $substitutes = array(
73 + T_DOLLAR_OPEN_CURLY_BRACES => array('$', '{'),
74 + );
75 +
72 76 /**
73 77 * Mapping between php internal tokens and php depend tokens.
74 78 *
189 193 T_PAAMAYIM_NEKUDOTAYIM => self::T_DOUBLE_COLON,
190 194 T_ENCAPSED_AND_WHITESPACE => self::T_ENCAPSED_AND_WHITESPACE,
191 195 T_CONSTANT_ENCAPSED_STRING => self::T_CONSTANT_ENCAPSED_STRING,
192 - T_DOLLAR_OPEN_CURLY_BRACES => self::T_CURLY_BRACE_OPEN,
196 + //T_DOLLAR_OPEN_CURLY_BRACES => self::T_CURLY_BRACE_OPEN,
193 197 );
194 198
195 199 /**
439 443 );
440 444
441 445 if (version_compare(phpversion(), '5.3.0alpha3') < 0) {
442 - $tokens = PHP_Depend_Tokenizer_PHP53NamespaceHelper::tokenize($source);
446 + $tempTokens = PHP_Depend_Tokenizer_PHP53NamespaceHelper::tokenize($source);
443 447 } else {
444 - $tokens = token_get_all($source);
448 + $tempTokens = token_get_all($source);
445 449 }
446 450
451 + $tokens = array();
452 + foreach ($tempTokens as $tempToken) {
453 + $temp = (array) $tempToken;
454 + $temp = $temp[0];
455 + if (isset(self::$substitutes[$temp])) {
456 + foreach (self::$substitutes[$temp] as $token) {
457 + $tokens[] = $token;
458 + }
459 + } else {
460 + $tokens[] = $tempToken;
461 + }
462 + }
463 +
464 +
447 465 reset($tokens);
448 466
449 467 // Is the current token between an opening and a closing php tag?