Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collections/UtilityMethodTestCase: sync with phpcs 3.x/PHP 8.0 identifier name tokens change #217

Merged
merged 2 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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