Skip to content

Commit d4d8657

Browse files
committed
Tokenizer/AttributesTest: move parse error test to own file
1 parent 91fbbd5 commit d4d8657

File tree

4 files changed

+47
-25
lines changed

4 files changed

+47
-25
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
// Intentional parse error.
4+
// This must be the only test in the file.
5+
6+
/* testInvalidAttribute */
7+
#[ThisIsNotAnAttribute
8+
function invalid_attribute_test() {}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Tests the support of PHP 8 attributes
4+
*
5+
* @author Alessandro Chitolina <[email protected]>
6+
* @copyright 2019 Squiz Pty Ltd (ABN 77 084 670 600)
7+
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/HEAD/licence.txt BSD Licence
8+
*/
9+
10+
namespace PHP_CodeSniffer\Tests\Core\Tokenizers\PHP;
11+
12+
use PHP_CodeSniffer\Tests\Core\Tokenizers\AbstractTokenizerTestCase;
13+
14+
final class AttributesParseError1Test extends AbstractTokenizerTestCase
15+
{
16+
17+
18+
/**
19+
* Test that invalid attribute (or comment starting with #[ and without ]) are parsed correctly.
20+
*
21+
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
22+
* @covers PHP_CodeSniffer\Tokenizers\PHP::findCloser
23+
* @covers PHP_CodeSniffer\Tokenizers\PHP::parsePhpAttribute
24+
*
25+
* @return void
26+
*/
27+
public function testInvalidAttribute()
28+
{
29+
$tokens = $this->phpcsFile->getTokens();
30+
31+
$attribute = $this->getTargetToken('/* testInvalidAttribute */', T_ATTRIBUTE);
32+
33+
$this->assertArrayHasKey('attribute_closer', $tokens[$attribute]);
34+
$this->assertNull($tokens[$attribute]['attribute_closer']);
35+
36+
}//end testInvalidAttribute()
37+
38+
39+
}//end class

tests/Core/Tokenizers/PHP/AttributesTest.inc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,3 @@ function attribute_containing_text_looking_like_close_tag() {}
8484
'reason: <https://some-website/reason?>'
8585
)]
8686
function attribute_containing_mulitline_text_looking_like_close_tag() {}
87-
88-
/* testInvalidAttribute */
89-
#[ThisIsNotAnAttribute
90-
function invalid_attribute_test() {}

tests/Core/Tokenizers/PHP/AttributesTest.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -581,27 +581,6 @@ public static function dataAttributeOnTextLookingLikeCloseTag()
581581
}//end dataAttributeOnTextLookingLikeCloseTag()
582582

583583

584-
/**
585-
* Test that invalid attribute (or comment starting with #[ and without ]) are parsed correctly.
586-
*
587-
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
588-
* @covers PHP_CodeSniffer\Tokenizers\PHP::findCloser
589-
* @covers PHP_CodeSniffer\Tokenizers\PHP::parsePhpAttribute
590-
*
591-
* @return void
592-
*/
593-
public function testInvalidAttribute()
594-
{
595-
$tokens = $this->phpcsFile->getTokens();
596-
597-
$attribute = $this->getTargetToken('/* testInvalidAttribute */', T_ATTRIBUTE);
598-
599-
$this->assertArrayHasKey('attribute_closer', $tokens[$attribute]);
600-
$this->assertNull($tokens[$attribute]['attribute_closer']);
601-
602-
}//end testInvalidAttribute()
603-
604-
605584
/**
606585
* Test that nested attributes are parsed correctly.
607586
*

0 commit comments

Comments
 (0)