Skip to content

Commit

Permalink
Merge pull request #217 from PHPCSStandards/collections/sync-with-php…
Browse files Browse the repository at this point in the history
…cs-3.x-identifier-names

Collections/UtilityMethodTestCase: sync with phpcs 3.x/PHP 8.0 identifier name tokens change
  • Loading branch information
jrfnl committed Sep 21, 2020
2 parents 242eac3 + 91f2250 commit 8d7d32e
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 6 deletions.
10 changes: 9 additions & 1 deletion PHPCSUtils/TestUtils/UtilityMethodTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,15 @@ public static function resetTestFile()
*/
public static function usesPhp8NameTokens()
{
return \version_compare(\PHP_VERSION_ID, '80000', '>=') === true;
$version = Helper::getVersion();
if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
&& (\version_compare($version, '3.5.7', '<') === true
|| \version_compare($version, '4.0.0', '>=') === true)
) {
return true;
}

return false;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions PHPCSUtils/Tokens/Collections.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,11 @@ public static function nameTokens()
\T_STRING => \T_STRING,
];

/*
* PHP >= 8.0 in combination with PHPCS < 3.5.7 and all PHP versions in combination
* with PHPCS >= 3.5.7, though when using PHPCS 3.5.7 < 4.0.0, these tokens are
* not yet in use, i.e. the PHP 8.0 change is "undone" for PHPCS 3.x.
*/
if (\defined('T_NAME_QUALIFIED') === true) {
$tokens[\T_NAME_QUALIFIED] = \T_NAME_QUALIFIED;
}
Expand Down
7 changes: 6 additions & 1 deletion Tests/Tokens/Collections/NameTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace PHPCSUtils\Tests\Tokens\Collections;

use PHPCSUtils\BackCompat\Helper;
use PHPCSUtils\Tokens\Collections;
use PHPUnit\Framework\TestCase;

Expand All @@ -32,11 +33,15 @@ class NameTokensTest extends TestCase
*/
public function testNameTokens()
{
$version = Helper::getVersion();
$expected = [
\T_STRING => \T_STRING,
];

if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true) {
if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
|| (\version_compare($version, '3.5.7', '>=') === true
&& \version_compare($version, '4.0.0', '<') === true)
) {
$expected[\T_NAME_QUALIFIED] = \T_NAME_QUALIFIED;
$expected[\T_NAME_FULLY_QUALIFIED] = \T_NAME_FULLY_QUALIFIED;
$expected[\T_NAME_RELATIVE] = \T_NAME_RELATIVE;
Expand Down
7 changes: 6 additions & 1 deletion Tests/Tokens/Collections/NamespacedNameTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace PHPCSUtils\Tests\Tokens\Collections;

use PHPCSUtils\BackCompat\Helper;
use PHPCSUtils\Tokens\Collections;
use PHPUnit\Framework\TestCase;

Expand All @@ -32,13 +33,17 @@ class NamespacedNameTokensTest extends TestCase
*/
public function testNamespacedNameTokens()
{
$version = Helper::getVersion();
$expected = [
\T_NS_SEPARATOR => \T_NS_SEPARATOR,
\T_NAMESPACE => \T_NAMESPACE,
\T_STRING => \T_STRING,
];

if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true) {
if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
|| (\version_compare($version, '3.5.7', '>=') === true
&& \version_compare($version, '4.0.0', '<') === true)
) {
$expected[\T_NAME_QUALIFIED] = \T_NAME_QUALIFIED;
$expected[\T_NAME_FULLY_QUALIFIED] = \T_NAME_FULLY_QUALIFIED;
$expected[\T_NAME_RELATIVE] = \T_NAME_RELATIVE;
Expand Down
7 changes: 6 additions & 1 deletion Tests/Tokens/Collections/ParameterTypeTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace PHPCSUtils\Tests\Tokens\Collections;

use PHPCSUtils\BackCompat\Helper;
use PHPCSUtils\Tokens\Collections;
use PHPUnit\Framework\TestCase;

Expand All @@ -32,6 +33,7 @@ class ParameterTypeTokensTest extends TestCase
*/
public function testParameterTypeTokens()
{
$version = Helper::getVersion();
$expected = [
\T_CALLABLE => \T_CALLABLE,
\T_SELF => \T_SELF,
Expand All @@ -44,7 +46,10 @@ public function testParameterTypeTokens()
\T_STRING => \T_STRING,
];

if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true) {
if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
|| (\version_compare($version, '3.5.7', '>=') === true
&& \version_compare($version, '4.0.0', '<') === true)
) {
$expected[\T_NAME_QUALIFIED] = \T_NAME_QUALIFIED;
$expected[\T_NAME_FULLY_QUALIFIED] = \T_NAME_FULLY_QUALIFIED;
$expected[\T_NAME_RELATIVE] = \T_NAME_RELATIVE;
Expand Down
7 changes: 6 additions & 1 deletion Tests/Tokens/Collections/PropertyTypeTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace PHPCSUtils\Tests\Tokens\Collections;

use PHPCSUtils\BackCompat\Helper;
use PHPCSUtils\Tokens\Collections;
use PHPUnit\Framework\TestCase;

Expand All @@ -32,6 +33,7 @@ class PropertyTypeTokensTest extends TestCase
*/
public function testPropertyTypeTokens()
{
$version = Helper::getVersion();
$expected = [
\T_CALLABLE => \T_CALLABLE,
\T_SELF => \T_SELF,
Expand All @@ -44,7 +46,10 @@ public function testPropertyTypeTokens()
\T_STRING => \T_STRING,
];

if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true) {
if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
|| (\version_compare($version, '3.5.7', '>=') === true
&& \version_compare($version, '4.0.0', '<') === true)
) {
$expected[\T_NAME_QUALIFIED] = \T_NAME_QUALIFIED;
$expected[\T_NAME_FULLY_QUALIFIED] = \T_NAME_FULLY_QUALIFIED;
$expected[\T_NAME_RELATIVE] = \T_NAME_RELATIVE;
Expand Down
7 changes: 6 additions & 1 deletion Tests/Tokens/Collections/ReturnTypeTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace PHPCSUtils\Tests\Tokens\Collections;

use PHPCSUtils\BackCompat\Helper;
use PHPCSUtils\Tokens\Collections;
use PHPUnit\Framework\TestCase;

Expand All @@ -32,6 +33,7 @@ class ReturnTypeTokensTest extends TestCase
*/
public function testReturnTypeTokens()
{
$version = Helper::getVersion();
$expected = [
\T_CALLABLE => \T_CALLABLE,
\T_SELF => \T_SELF,
Expand All @@ -46,7 +48,10 @@ public function testReturnTypeTokens()
\T_STRING => \T_STRING,
];

if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true) {
if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
|| (\version_compare($version, '3.5.7', '>=') === true
&& \version_compare($version, '4.0.0', '<') === true)
) {
$expected[\T_NAME_QUALIFIED] = \T_NAME_QUALIFIED;
$expected[\T_NAME_FULLY_QUALIFIED] = \T_NAME_FULLY_QUALIFIED;
$expected[\T_NAME_RELATIVE] = \T_NAME_RELATIVE;
Expand Down

0 comments on commit 8d7d32e

Please sign in to comment.