Skip to content

Commit

Permalink
NewAttributes: add one additional test case
Browse files Browse the repository at this point in the history
... as per the discussion and similar test case upstream in squizlabs/PHP_CodeSniffer 3294.
  • Loading branch information
jrfnl committed Apr 13, 2021
1 parent 900d1a2 commit 1ab6aeb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion PHPCompatibility/Tests/Attributes/NewAttributesUnitTest.inc
Expand Up @@ -102,6 +102,11 @@ class AnotherMultilineAttributeTest

// This code will cause a tokenizer error in PHP < 8.0. This must be the last test in the file!
#[DeprecationReason('reason: <https://some-website/reason?>')]
function main() {}
function attribute_containing_text_looking_like_close_tag() {}
const APP_SECRET = 'app-secret';
echo "Test\n";

#[DeprecationReason(
'reason: <https://some-website/reason?>'
)]
function attribute_containing_mulitline_text_looking_like_close_tag() {}
15 changes: 14 additions & 1 deletion PHPCompatibility/Tests/Attributes/NewAttributesUnitTest.php
Expand Up @@ -11,6 +11,7 @@
namespace PHPCompatibility\Tests\Attributes;

use PHPCompatibility\Tests\BaseSniffTest;
use PHPCSUtils\BackCompat\Helper;

/**
* Test the NewAttributes sniff.
Expand Down Expand Up @@ -55,7 +56,7 @@ public function testNewAttributes($line, $found = '')
*/
public function dataNewAttributes()
{
return [
$data = [
[17],
[20],
[23],
Expand Down Expand Up @@ -93,6 +94,18 @@ public function dataNewAttributes()
[96, '#[Assert\Text(["message" => "text"]), Assert\Domain(["message" => "text"]), Assert\Id(Assert\Id::REGEX[10]), ]'],
[104],
];

/*
* In PHP < 8.0 in combination with PHPCS < 3.6.1, anything after the test case on
* line 104 will be tokenized as `T_INLINE_HTML` and undetectable.
*/
if (version_compare(Helper::getVersion(), '3.6.1', '>=') === true
|| version_compare(PHP_VERSION_ID, '80000', '>=') === true
) {
$data[] = [109];
}

return $data;
}


Expand Down

0 comments on commit 1ab6aeb

Please sign in to comment.